@@ -154,10 +154,8 @@ export class JobProcessor {
154
154
'job [%s] lock status: shouldLock = %s' ,
155
155
name ,
156
156
shouldLock ,
157
- status ?. locked ,
158
- this . jobQueue . length ,
159
- this . lockedJobs . length ,
160
- this . totalLockLimit
157
+ `${ status ?. locked } >= ${ jobDefinition ?. lockLimit } ` ,
158
+ `${ this . lockedJobs . length } >= ${ this . totalLockLimit } `
161
159
) ;
162
160
return shouldLock ;
163
161
}
@@ -240,6 +238,8 @@ export class JobProcessor {
240
238
this . lockedJobs . push ( jobToEnqueue ) ;
241
239
this . enqueueJob ( jobToEnqueue ) ;
242
240
this . jobProcessing ( ) ;
241
+ } else {
242
+ log . extend ( 'lockOnTheFly' ) ( 'cannot lock job [%s] on the fly' , job . attrs . name ) ;
243
243
}
244
244
}
245
245
} finally {
@@ -378,6 +378,9 @@ export class JobProcessor {
378
378
this . jobProcessing ( ) ;
379
379
} , runIn ) ;
380
380
}
381
+
382
+ // additionally run again and check if there are more jobs that we can process right now (as long concurrency not reached)
383
+ setImmediate ( ( ) => this . jobProcessing ( ) ) ;
381
384
}
382
385
383
386
/**
@@ -437,8 +440,8 @@ export class JobProcessor {
437
440
log . extend ( 'runOrRetry' ) ( '[%s:%s] processing job' , job . attrs . name , job . attrs . _id ) ;
438
441
439
442
// check if the job is still alive
440
- const checkIfJobIsDead = ( ) => {
441
- // check every processInterval
443
+ const checkIfJobIsStillAlive = ( ) => {
444
+ // check every "this.agenda.definitions[job.attrs.name].lockLifetime"" (or at mininum every processEvery)
442
445
return new Promise ( ( resolve , reject ) =>
443
446
setTimeout ( ( ) => {
444
447
if ( job . isDead ( ) ) {
@@ -456,13 +459,13 @@ export class JobProcessor {
456
459
resolve ( ) ;
457
460
return ;
458
461
}
459
- resolve ( checkIfJobIsDead ( ) ) ;
460
- } , this . processEvery )
462
+ resolve ( checkIfJobIsStillAlive ( ) ) ;
463
+ } , Math . max ( this . processEvery , this . agenda . definitions [ job . attrs . name ] . lockLifetime ) )
461
464
) ;
462
465
} ;
463
466
464
467
// CALL THE ACTUAL METHOD TO PROCESS THE JOB!!!
465
- await Promise . race ( [ job . run ( ) , checkIfJobIsDead ( ) ] ) ;
468
+ await Promise . race ( [ job . run ( ) , checkIfJobIsStillAlive ( ) ] ) ;
466
469
467
470
log . extend ( 'runOrRetry' ) (
468
471
'[%s:%s] processing job successfull' ,
0 commit comments