@@ -117,9 +117,7 @@ export class KnexAdapter implements Adapter {
117117
118118 // Update job to active status
119119 // For SQLite (no SKIP LOCKED), add status='pending' guard to prevent double-claim
120- const updateQuery = trx ( this . #jobsTable)
121- . where ( 'id' , job . id )
122- . where ( 'queue' , queue )
120+ const updateQuery = trx ( this . #jobsTable) . where ( 'id' , job . id ) . where ( 'queue' , queue )
123121
124122 if ( ! this . #supportsSkipLocked( ) ) {
125123 updateQuery . where ( 'status' , 'pending' )
@@ -178,19 +176,21 @@ export class KnexAdapter implements Adapter {
178176 const priority = jobData . priority ?? DEFAULT_PRIORITY
179177 const score = calculateScore ( priority , now )
180178
181- await trx ( this . #jobsTable)
182- . where ( 'id' , job . id )
183- . where ( 'queue' , queue )
184- . update ( {
185- status : 'pending' ,
186- score,
187- execute_at : null ,
188- } )
179+ await trx ( this . #jobsTable) . where ( 'id' , job . id ) . where ( 'queue' , queue ) . update ( {
180+ status : 'pending' ,
181+ score,
182+ execute_at : null ,
183+ } )
189184 }
190185 } )
191186 }
192187
193- async completeJob ( jobId : string , queue : string , removeOnComplete ?: JobRetention ) : Promise < void > {
188+ async completeJob (
189+ jobId : string ,
190+ queue : string ,
191+ removeOnComplete ?: JobRetention ,
192+ output ?: any
193+ ) : Promise < void > {
194194 const { keep, maxAge, maxCount } = resolveRetention ( removeOnComplete )
195195
196196 if ( ! keep ) {
@@ -213,6 +213,7 @@ export class KnexAdapter implements Adapter {
213213 worker_id : null ,
214214 acquired_at : null ,
215215 finished_at : now ,
216+ output : output ? JSON . stringify ( output ) : null ,
216217 } )
217218
218219 if ( ! updated ) {
@@ -276,6 +277,7 @@ export class KnexAdapter implements Adapter {
276277 status : row . status as JobStatus ,
277278 data : jobData ,
278279 finishedAt : row . finished_at ? Number ( row . finished_at ) : undefined ,
280+ output : row . output ? JSON . parse ( row . output ) : undefined ,
279281 error : row . error || undefined ,
280282 }
281283 }
@@ -331,33 +333,27 @@ export class KnexAdapter implements Adapter {
331333
332334 if ( retryAt && retryAt . getTime ( ) > now ) {
333335 // Move to delayed
334- await this . #connection( this . #jobsTable)
335- . where ( 'id' , jobId )
336- . where ( 'queue' , queue )
337- . update ( {
338- status : 'delayed' ,
339- data : updatedData ,
340- worker_id : null ,
341- acquired_at : null ,
342- score : null ,
343- execute_at : retryAt . getTime ( ) ,
344- } )
336+ await this . #connection( this . #jobsTable) . where ( 'id' , jobId ) . where ( 'queue' , queue ) . update ( {
337+ status : 'delayed' ,
338+ data : updatedData ,
339+ worker_id : null ,
340+ acquired_at : null ,
341+ score : null ,
342+ execute_at : retryAt . getTime ( ) ,
343+ } )
345344 } else {
346345 // Move back to pending
347346 const priority = jobData . priority ?? DEFAULT_PRIORITY
348347 const score = calculateScore ( priority , now )
349348
350- await this . #connection( this . #jobsTable)
351- . where ( 'id' , jobId )
352- . where ( 'queue' , queue )
353- . update ( {
354- status : 'pending' ,
355- data : updatedData ,
356- worker_id : null ,
357- acquired_at : null ,
358- score,
359- execute_at : null ,
360- } )
349+ await this . #connection( this . #jobsTable) . where ( 'id' , jobId ) . where ( 'queue' , queue ) . update ( {
350+ status : 'pending' ,
351+ data : updatedData ,
352+ worker_id : null ,
353+ acquired_at : null ,
354+ score,
355+ execute_at : null ,
356+ } )
361357 }
362358 }
363359
@@ -458,10 +454,7 @@ export class KnexAdapter implements Adapter {
458454
459455 if ( currentStalledCount >= maxStalledCount ) {
460456 // Fail permanently - remove the job
461- await trx ( this . #jobsTable)
462- . where ( 'id' , row . id )
463- . where ( 'queue' , queue )
464- . delete ( )
457+ await trx ( this . #jobsTable) . where ( 'id' , row . id ) . where ( 'queue' , queue ) . delete ( )
465458 } else {
466459 // Recover: increment stalledCount and put back in pending
467460 jobData . stalledCount = currentStalledCount + 1
@@ -534,9 +527,9 @@ export class KnexAdapter implements Adapter {
534527 }
535528
536529 async getSchedule ( id : string ) : Promise < ScheduleData | null > {
537- const row = ( await this . #connection( this . #schedulesTable)
538- . where ( 'id' , id )
539- . first ( ) ) as ScheduleRow | undefined
530+ const row = ( await this . #connection( this . #schedulesTable) . where ( 'id' , id ) . first ( ) ) as
531+ | ScheduleRow
532+ | undefined
540533 if ( ! row ) return null
541534
542535 return this . #rowToScheduleData( row )
@@ -565,16 +558,12 @@ export class KnexAdapter implements Adapter {
565558 if ( updates . runCount !== undefined ) data . run_count = updates . runCount
566559
567560 if ( Object . keys ( data ) . length > 0 ) {
568- await this . #connection( this . #schedulesTable)
569- . where ( 'id' , id )
570- . update ( data )
561+ await this . #connection( this . #schedulesTable) . where ( 'id' , id ) . update ( data )
571562 }
572563 }
573564
574565 async deleteSchedule ( id : string ) : Promise < void > {
575- await this . #connection( this . #schedulesTable)
576- . where ( 'id' , id )
577- . delete ( )
566+ await this . #connection( this . #schedulesTable) . where ( 'id' , id ) . delete ( )
578567 }
579568
580569 async claimDueSchedule ( ) : Promise < ScheduleData | null > {
@@ -629,13 +618,11 @@ export class KnexAdapter implements Adapter {
629618 }
630619
631620 // Update atomically
632- await trx ( this . #schedulesTable)
633- . where ( 'id' , row . id )
634- . update ( {
635- next_run_at : nextRunAt ,
636- last_run_at : now ,
637- run_count : newRunCount ,
638- } )
621+ await trx ( this . #schedulesTable) . where ( 'id' , row . id ) . update ( {
622+ next_run_at : nextRunAt ,
623+ last_run_at : now ,
624+ run_count : newRunCount ,
625+ } )
639626
640627 // Return schedule data (before update state for payload)
641628 return this . #rowToScheduleData( row )
0 commit comments