File tree 4 files changed +10
-6
lines changed
4 files changed +10
-6
lines changed Original file line number Diff line number Diff line change @@ -162,7 +162,7 @@ export class Job<DATA = unknown | void> {
162
162
163
163
async isRunning ( ) : Promise < boolean > {
164
164
const definition = this . agenda . definitions [ this . attrs . name ] ;
165
- if ( ! definition ) {
165
+ if ( ! definition || ! this . agenda . isActiveJobProcessor ( ) ) {
166
166
// we have no job definition, therfore we are not the job processor, but a client call
167
167
// so we get the real state from database
168
168
await this . fetchStatus ( ) ;
@@ -198,7 +198,7 @@ export class Job<DATA = unknown | void> {
198
198
199
199
async isDead ( ) : Promise < boolean > {
200
200
const definition = this . agenda . definitions [ this . attrs . name ] ;
201
- if ( ! definition ) {
201
+ if ( ! definition || ! this . agenda . isActiveJobProcessor ( ) ) {
202
202
// we have no job definition, therfore we are not the job processor, but a client call
203
203
// so we get the real state from database
204
204
await this . fetchStatus ( ) ;
Original file line number Diff line number Diff line change @@ -500,7 +500,7 @@ export class JobProcessor {
500
500
}
501
501
502
502
resolve ( checkIfJobIsStillAlive ( ) ) ;
503
- } , Math . max ( this . processEvery , this . agenda . definitions [ job . attrs . name ] . lockLifetime / 2 ) )
503
+ } , Math . max ( this . processEvery / 2 , this . agenda . definitions [ job . attrs . name ] . lockLifetime / 2 ) )
504
504
) ;
505
505
} ;
506
506
Original file line number Diff line number Diff line change @@ -64,6 +64,10 @@ export class Agenda extends EventEmitter {
64
64
65
65
readonly ready : Promise < void > ;
66
66
67
+ isActiveJobProcessor ( ) : boolean {
68
+ return ! ! this . jobProcessor ;
69
+ }
70
+
67
71
async getRunningStats ( fullDetails = false ) : Promise < IAgendaStatus > {
68
72
if ( ! this . jobProcessor ) {
69
73
throw new Error ( 'agenda not running!' ) ;
@@ -408,8 +412,6 @@ export class Agenda extends EventEmitter {
408
412
this . attrs . processEvery
409
413
) ;
410
414
411
- await this . jobProcessor . process ( ) ;
412
-
413
415
this . on ( 'processJob' , job => this . jobProcessor ?. process ( job ) ) ;
414
416
}
415
417
Original file line number Diff line number Diff line change @@ -77,6 +77,8 @@ describe('JobProcessor', () => {
77
77
agenda . now ( 'test' ) ;
78
78
await agenda . start ( ) ;
79
79
80
+ await new Promise ( resolve => agenda . on ( 'start:test' , resolve ) ) ;
81
+
80
82
const status = await agenda . getRunningStats ( ) ;
81
83
expect ( status ) . to . have . property ( 'jobStatus' ) ;
82
84
if ( status . jobStatus ) {
@@ -155,7 +157,7 @@ describe('JobProcessor', () => {
155
157
'test long' ,
156
158
async ( ) => {
157
159
jobStarted = true ;
158
- await new Promise ( resolve => setTimeout ( resolve , 1000 ) ) ;
160
+ await new Promise ( resolve => setTimeout ( resolve , 2500 ) ) ;
159
161
} ,
160
162
{ lockLifetime : 500 }
161
163
) ;
You can’t perform that action at this time.
0 commit comments