Skip to content

Commit

Permalink
refactor(job-scheduler): startDate assignment
Browse files Browse the repository at this point in the history
  • Loading branch information
manast committed Oct 11, 2024
1 parent ed047f7 commit 76e40ae
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
4 changes: 1 addition & 3 deletions src/classes/job-scheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export class JobScheduler extends QueueBase {
const prevMillis = opts.prevMillis || 0;

// Check if we have a start date for the repeatable job
const { startDate } = repeatOpts;
const { startDate, ...filteredRepeatOpts } = repeatOpts;
if (startDate) {
const startMillis = new Date(startDate).getTime();
now = startMillis > now ? startMillis : now;
Expand Down Expand Up @@ -105,8 +105,6 @@ export class JobScheduler extends QueueBase {
);
}

const { startDate, ...filteredRepeatOpts } = repeatOpts;

return this.createNextJob<T, R, N>(
jobName,
nextMillis,
Expand Down
7 changes: 2 additions & 5 deletions tests/test_job_scheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -720,8 +720,8 @@ describe('Job Scheduler', function () {
worker.on('completed', async job => {
try {
if (prev && counter === 1) {
expect(prev.timestamp).to.be.lt(job.timestamp);
expect(job.timestamp - prev.timestamp).to.be.gte(100);
expect(prev.timestamp).to.be.lte(job.timestamp);
expect(job.timestamp - prev.timestamp).to.be.lte(1);
} else if (prev) {
expect(prev.timestamp).to.be.lt(job.timestamp);
expect(job.timestamp - prev.timestamp).to.be.gte(2000);
Expand All @@ -741,13 +741,10 @@ describe('Job Scheduler', function () {
'repeat',
{
every: 2000,
immediately: true,
},
{ data: { foo: 'bar' } },
);

this.clock.tick(nextTick);

await completing;

await worker.close();
Expand Down

0 comments on commit 76e40ae

Please sign in to comment.