Skip to content

Commit e6ea7e2

Browse files
committed
fix: isRunning, check if db returns a result
1 parent 2bd7638 commit e6ea7e2

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/Job.ts

+5
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,11 @@ export class Job<DATA = unknown | void> {
153153
// we have no job definition, therfore we are not the job processor, but a client call
154154
// so we get the real state from database
155155
const dbJob = await this.agenda.db.getJobs({ _id: this.attrs._id });
156+
if (!dbJob || dbJob.length === 0) {
157+
// @todo: should we just return false instead? a finished job could have been removed from database,
158+
// and then this would throw...
159+
throw new Error(`job with id ${this.attrs._id} not found in database`);
160+
}
156161
this.attrs.lastRunAt = dbJob[0].lastRunAt;
157162
this.attrs.lastFinishedAt = dbJob[0].lastFinishedAt;
158163
}

0 commit comments

Comments
 (0)