File tree 1 file changed +14
-1
lines changed
1 file changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -152,7 +152,16 @@ export class Job<DATA = unknown | void> {
152
152
return this ;
153
153
}
154
154
155
- isRunning ( ) : boolean {
155
+ async isRunning ( ) : Promise < boolean > {
156
+ const definition = this . agenda . definitions [ this . attrs . name ] ;
157
+ if ( ! definition ) {
158
+ // we have no job definition, therfore we are not the job processor, but a client call
159
+ // so we get the real state from database
160
+ const dbJob = await this . agenda . db . getJobs ( { _id : this . attrs . _id } ) ;
161
+ this . attrs . lastRunAt = dbJob [ 0 ] . lastRunAt ;
162
+ this . attrs . lastFinishedAt = dbJob [ 0 ] . lastFinishedAt ;
163
+ }
164
+
156
165
if ( ! this . attrs . lastRunAt ) {
157
166
return false ;
158
167
}
@@ -183,6 +192,10 @@ export class Job<DATA = unknown | void> {
183
192
184
193
isDead ( ) : boolean {
185
194
const definition = this . agenda . definitions [ this . attrs . name ] ;
195
+ if ( ! definition ) {
196
+ console . warn ( 'this method is only callable from an agenda job processor' ) ;
197
+ return false ;
198
+ }
186
199
const lockDeadline = new Date ( Date . now ( ) - definition . lockLifetime ) ;
187
200
188
201
// This means a job has "expired", as in it has not been "touched" within the lockoutTime
You can’t perform that action at this time.
0 commit comments