@@ -22,6 +22,24 @@ export interface KnexAdapterOptions {
2222}
2323
2424type KnexConfig = Knex | Knex . Config
25+ type DbRow = Record < string , unknown >
26+
27+ interface ScheduleRow extends DbRow {
28+ id : string
29+ name : string
30+ payload : unknown
31+ cron_expression : string | null
32+ every_ms : number | string | null
33+ timezone : string | null
34+ from_date : Date | string | number | null
35+ to_date : Date | string | number | null
36+ run_limit : number | string | null
37+ run_count : number | string | null
38+ next_run_at : Date | string | number | null
39+ last_run_at : Date | string | number | null
40+ status : string
41+ created_at : Date | string | number | null
42+ }
2543
2644/**
2745 * Create a new Knex adapter factory.
@@ -516,9 +534,9 @@ export class KnexAdapter implements Adapter {
516534 }
517535
518536 async getSchedule ( id : string ) : Promise < ScheduleData | null > {
519- const row = await this . #connection( this . #schedulesTable)
537+ const row = ( await this . #connection( this . #schedulesTable)
520538 . where ( 'id' , id )
521- . first ( )
539+ . first ( ) ) as ScheduleRow | undefined
522540 if ( ! row ) return null
523541
524542 return this . #rowToScheduleData( row )
@@ -531,15 +549,15 @@ export class KnexAdapter implements Adapter {
531549 query = query . where ( 'status' , options . status )
532550 }
533551
534- const rows = await query
535- return rows . map ( ( row : any ) => this . #rowToScheduleData( row ) )
552+ const rows = ( await query ) as ScheduleRow [ ]
553+ return rows . map ( ( row ) => this . #rowToScheduleData( row ) )
536554 }
537555
538556 async updateSchedule (
539557 id : string ,
540558 updates : Partial < Pick < ScheduleData , 'status' | 'nextRunAt' | 'lastRunAt' | 'runCount' > >
541559 ) : Promise < void > {
542- const data : Record < string , any > = { }
560+ const data : Record < string , unknown > = { }
543561
544562 if ( updates . status !== undefined ) data . status = updates . status
545563 if ( updates . nextRunAt !== undefined ) data . next_run_at = updates . nextRunAt
@@ -581,12 +599,12 @@ export class KnexAdapter implements Adapter {
581599 query = query . forUpdate ( ) . skipLocked ( )
582600 }
583601
584- const row = await query . first ( )
602+ const row = ( await query . first ( ) ) as ScheduleRow | undefined
585603 if ( ! row ) return null
586604
587605 // Calculate next run time
588606 let nextRunAt : Date | null = null
589- const newRunCount = ( row . run_count ?? 0 ) + 1
607+ const newRunCount = Number ( row . run_count ?? 0 ) + 1
590608
591609 if ( row . every_ms ) {
592610 nextRunAt = new Date ( now . getTime ( ) + Number ( row . every_ms ) )
@@ -601,7 +619,7 @@ export class KnexAdapter implements Adapter {
601619 }
602620
603621 // Check if limit will be reached
604- if ( row . run_limit !== null && newRunCount >= row . run_limit ) {
622+ if ( row . run_limit !== null && newRunCount >= Number ( row . run_limit ) ) {
605623 nextRunAt = null
606624 }
607625
@@ -624,7 +642,7 @@ export class KnexAdapter implements Adapter {
624642 } )
625643 }
626644
627- #rowToScheduleData( row : any ) : ScheduleData {
645+ #rowToScheduleData( row : ScheduleRow ) : ScheduleData {
628646 return {
629647 id : row . id ,
630648 name : row . name ,
@@ -638,7 +656,7 @@ export class KnexAdapter implements Adapter {
638656 runCount : Number ( row . run_count ?? 0 ) ,
639657 nextRunAt : row . next_run_at ? new Date ( row . next_run_at ) : null ,
640658 lastRunAt : row . last_run_at ? new Date ( row . last_run_at ) : null ,
641- status : row . status === 'cancelled' ? 'paused' : row . status ,
659+ status : row . status === 'paused' || row . status === ' cancelled' ? 'paused' : 'active' ,
642660 createdAt : row . created_at ? new Date ( row . created_at ) : new Date ( ) ,
643661 }
644662 }
0 commit comments