Skip to content

Commit

Permalink
fix: nextRunAt value can be null
Browse files Browse the repository at this point in the history
  • Loading branch information
simllll committed Dec 5, 2021
1 parent 47ff693 commit e39cfd0
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/Job.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export class Job<DATA = unknown | void> {
...args,
// Set defaults if undefined
priority: parsePriority(args.priority),
nextRunAt: args.nextRunAt || new Date(),
nextRunAt: args.nextRunAt === undefined ? new Date() : args.nextRunAt,
type: args.type
};
}
Expand Down
7 changes: 1 addition & 6 deletions src/JobProcessingQueue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export class JobProcessingQueue {
| undefined;
},
handledJobs: IJobParameters['_id'][]
): (JobWithId & { attrs: IJobParameters & { nextRunAt: Date } }) | undefined {
): (JobWithId & { attrs: IJobParameters & { nextRunAt?: Date | null } }) | undefined {
const next = (Object.keys(this._queue) as unknown as number[]).reverse().find(i => {
const def = this.agenda.definitions[this._queue[i].attrs.name];
const status = jobStatus[this._queue[i].attrs.name];
Expand All @@ -116,11 +116,6 @@ export class JobProcessingQueue {
!handledJobs.includes(this._queue[i].attrs._id) &&
(!status || !def.concurrency || status.running < def.concurrency)
) {
if (!this._queue[i].attrs.nextRunAt) {
// eslint-disable-next-line no-console
console.log('this._queue[i]', this._queue[i].attrs);
throw new Error('no nextRunAt date');
}
return true;
}
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/JobProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ export class JobProcessor {

// If the 'nextRunAt' time is older than the current time, run the job
// Otherwise, setTimeout that gets called at the time of 'nextRunAt'
if (job.attrs.nextRunAt <= now) {
if (!job.attrs.nextRunAt || job.attrs.nextRunAt <= now) {
log.extend('jobProcessing')(
'[%s:%s] nextRunAt is in the past, run the job immediately',
job.attrs.name,
Expand Down

0 comments on commit e39cfd0

Please sign in to comment.