Skip to content

Commit

Permalink
fix: isRunning, check if db returns a result
Browse files Browse the repository at this point in the history
  • Loading branch information
simllll committed Oct 25, 2020
1 parent 2bd7638 commit e6ea7e2
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ export class Job<DATA = unknown | void> {
// we have no job definition, therfore we are not the job processor, but a client call
// so we get the real state from database
const dbJob = await this.agenda.db.getJobs({ _id: this.attrs._id });
if (!dbJob || dbJob.length === 0) {
// @todo: should we just return false instead? a finished job could have been removed from database,
// and then this would throw...
throw new Error(`job with id ${this.attrs._id} not found in database`);
}
this.attrs.lastRunAt = dbJob[0].lastRunAt;
this.attrs.lastFinishedAt = dbJob[0].lastFinishedAt;
}
Expand Down

0 comments on commit e6ea7e2

Please sign in to comment.