Skip to content

Commit e39cfd0

Browse files
committed
fix: nextRunAt value can be null
1 parent 47ff693 commit e39cfd0

File tree

3 files changed

+3
-8
lines changed

3 files changed

+3
-8
lines changed

src/Job.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export class Job<DATA = unknown | void> {
6262
...args,
6363
// Set defaults if undefined
6464
priority: parsePriority(args.priority),
65-
nextRunAt: args.nextRunAt || new Date(),
65+
nextRunAt: args.nextRunAt === undefined ? new Date() : args.nextRunAt,
6666
type: args.type
6767
};
6868
}

src/JobProcessingQueue.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export class JobProcessingQueue {
102102
| undefined;
103103
},
104104
handledJobs: IJobParameters['_id'][]
105-
): (JobWithId & { attrs: IJobParameters & { nextRunAt: Date } }) | undefined {
105+
): (JobWithId & { attrs: IJobParameters & { nextRunAt?: Date | null } }) | undefined {
106106
const next = (Object.keys(this._queue) as unknown as number[]).reverse().find(i => {
107107
const def = this.agenda.definitions[this._queue[i].attrs.name];
108108
const status = jobStatus[this._queue[i].attrs.name];
@@ -116,11 +116,6 @@ export class JobProcessingQueue {
116116
!handledJobs.includes(this._queue[i].attrs._id) &&
117117
(!status || !def.concurrency || status.running < def.concurrency)
118118
) {
119-
if (!this._queue[i].attrs.nextRunAt) {
120-
// eslint-disable-next-line no-console
121-
console.log('this._queue[i]', this._queue[i].attrs);
122-
throw new Error('no nextRunAt date');
123-
}
124119
return true;
125120
}
126121
return false;

src/JobProcessor.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ export class JobProcessor {
409409

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

0 commit comments

Comments
 (0)