Skip to content

Commit

Permalink
fix(repeatable): honor endDate fixes #1573
Browse files Browse the repository at this point in the history
  • Loading branch information
manast authored Jul 16, 2021
1 parent 0dc7b12 commit 7f0db0e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
5 changes: 5 additions & 0 deletions lib/repeatable.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ module.exports = function(Queue) {
}

let now = Date.now();

if (!_.isUndefined(repeat.endDate) && now > new Date(repeat.endDate)) {
return Promise.resolve();
}

now = prevMillis < now ? now : prevMillis;

const nextMillis = getNextMillis(now, repeat);
Expand Down
32 changes: 31 additions & 1 deletion test/test_repeat.js
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,6 @@ describe('repeat', () => {
}, done);
});

// Skip test that only fails on travis
it('should use ".every" as a valid interval', function(done) {
const _this = this;
const interval = ONE_SECOND * 2;
Expand Down Expand Up @@ -802,4 +801,35 @@ describe('repeat', () => {
}
});
});

it('it should stop repeating after endDate', async function() {
const every = 100;
const date = new Date('2017-02-07 9:24:00');
this.clock.setSystemTime(date);

await queue.add(
{ id: 'my id' },
{
repeat: {
endDate: Date.now() + 1000,
every: 100
}
}
);

this.clock.tick(every + 1);

let processed = 0;
queue.process(async () => {
this.clock.tick(every);
processed++;
});

await utils.sleep(1100);

const delayed = await queue.getDelayed();

expect(delayed).to.have.length(0);
expect(processed).to.be.equal(10);
});
});

0 comments on commit 7f0db0e

Please sign in to comment.