Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(repeat): throw error when endDate is pointing to the past #2574

Merged
merged 1 commit into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading