@@ -25,6 +25,23 @@ export class JobProcessor {
25
25
// eslint-disable-next-line @typescript-eslint/no-var-requires,global-require
26
26
const { version } = require ( '../package.json' ) ;
27
27
28
+ const jobStatus =
29
+ ( typeof Object . fromEntries === 'function' &&
30
+ Object . fromEntries (
31
+ Object . keys ( this . jobStatus ) . map ( job => [
32
+ job ,
33
+ {
34
+ ...this . jobStatus [ job ] ! ,
35
+ config : this . agenda . definitions [ job ]
36
+ }
37
+ ] )
38
+ ) ) ||
39
+ undefined ;
40
+
41
+ if ( typeof Object . fromEntries !== 'function' ) {
42
+ console . warn ( 'job status not available due to too old node version' ) ;
43
+ }
44
+
28
45
return {
29
46
version,
30
47
queueName : this . agenda . attrs . name ,
@@ -34,15 +51,7 @@ export class JobProcessor {
34
51
maxConcurrency : this . maxConcurrency ,
35
52
processEvery : this . processEvery
36
53
} ,
37
- jobStatus : Object . fromEntries (
38
- Object . keys ( this . jobStatus ) . map ( job => [
39
- job ,
40
- {
41
- ...this . jobStatus [ job ] ! ,
42
- config : this . agenda . definitions [ job ]
43
- }
44
- ] )
45
- ) ,
54
+ jobStatus,
46
55
queuedJobs : this . jobQueue . length ,
47
56
runningJobs : ! fullDetails ? this . runningJobs . length : this . runningJobs ,
48
57
lockedJobs : ! fullDetails ? this . lockedJobs . length : this . lockedJobs ,
@@ -384,17 +393,10 @@ export class JobProcessor {
384
393
this . jobProcessing ( ) ;
385
394
} , runIn ) ;
386
395
}
387
- // console.log('this.localQueueProcessing', this.localQueueProcessing);
388
396
if ( this . localQueueProcessing < this . maxConcurrency && jobEnqueued ) {
389
397
// additionally run again and check if there are more jobs that we can process right now (as long concurrency not reached)
390
398
setImmediate ( ( ) => this . jobProcessing ( ) ) ;
391
- } /* else {
392
- console.log(
393
- 'NOT CALLING JOB PROCESSING AGAIN DUE TO',
394
- this.localQueueProcessing,
395
- this.maxConcurrency
396
- );
397
- } */
399
+ }
398
400
} finally {
399
401
this . localQueueProcessing -= 1 ;
400
402
}
@@ -424,9 +426,9 @@ export class JobProcessor {
424
426
( ! jobDefinition . concurrency || ! status || status . running < jobDefinition . concurrency ) &&
425
427
this . runningJobs . length < this . maxConcurrency
426
428
) {
427
- // NOTE: Shouldn't we update the 'lockedAt' value in MongoDB so it can be picked up on restart?
428
- // -> not needed, as the timeout has been reached, and it will be picked up anyways again
429
429
if ( job . isDead ( ) ) {
430
+ // not needed to update lockedAt in databsase, as the timeout has been reached,
431
+ // and it will be picked up anyways again
430
432
log . extend ( 'runOrRetry' ) (
431
433
'[%s:%s] job lock has expired, freeing it up' ,
432
434
job . attrs . name ,
@@ -445,8 +447,7 @@ export class JobProcessor {
445
447
446
448
this . lockedJobs . splice ( lockedJobIndex , 1 ) ;
447
449
this . updateStatus ( job . attrs . name , 'locked' , - 1 ) ;
448
- this . jobProcessing ( ) ;
449
- return false ;
450
+ return true ;
450
451
}
451
452
452
453
const runJob = async ( ) => {
0 commit comments