Skip to content

Commit

Permalink
fix(repeat): throw error when endDate is pointing to the past (#2574)
Browse files Browse the repository at this point in the history
  • Loading branch information
roggervalf authored May 24, 2024
1 parent dff8e2e commit 5bd7990
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/classes/queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,12 @@ export class Queue<
opts?: JobsOptions,
): Promise<Job<DataType, ResultType, NameType>> {
if (opts && opts.repeat) {
if (opts.repeat.endDate) {
if (+new Date(opts.repeat.endDate) < Date.now()) {
throw new Error('End date must be greater than current timestamp');
}
}

return (await this.repeat).addNextRepeatableJob<
DataType,
ResultType,
Expand Down
17 changes: 17 additions & 0 deletions tests/test_repeat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,23 @@ describe('repeat', function () {
});
});

describe('when endDate is not greater than current timestamp', () => {
it('throws an error', async function () {
await expect(
queue.add(
'test',
{ foo: 'bar' },
{
repeat: {
endDate: Date.now() - 1000,
every: 100,
},
},
),
).to.be.rejectedWith('End date must be greater than current timestamp');
});
});

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

0 comments on commit 5bd7990

Please sign in to comment.