Skip to content

Commit

Permalink
fix(repeatable): remove repeat hash when removing repeatable job (#2676)
Browse files Browse the repository at this point in the history
  • Loading branch information
roggervalf authored Jul 26, 2024
1 parent 45fa04e commit 97a297d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/classes/scripts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ export class Scripts {
): string[] {
const queueKeys = this.queue.keys;

const keys = [queueKeys.repeat, queueKeys.delayed];
const keys = [queueKeys.repeat, queueKeys.delayed, queueKeys.events];

const args = [
legacyRepeatJobId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
Input:
KEYS[1] repeat jobs key
KEYS[2] delayed jobs key
KEYS[3] events key
ARGV[1] old repeat job id
ARGV[2] options concat
Expand All @@ -29,7 +30,7 @@ if millis then
local repeatJobId = ARGV[1] .. millis
if(rcall("ZREM", KEYS[2], repeatJobId) == 1) then
removeJobKeys(ARGV[4] .. repeatJobId)
rcall("XADD", ARGV[4] .. "events", "*", "event", "removed", "jobId", repeatJobId, "prev", "delayed");
rcall("XADD", KEYS[3], "*", "event", "removed", "jobId", repeatJobId, "prev", "delayed");
end
end

Expand All @@ -45,11 +46,12 @@ if millis then
local repeatJobId = "repeat:" .. ARGV[3] .. ":" .. millis
if(rcall("ZREM", KEYS[2], repeatJobId) == 1) then
removeJobKeys(ARGV[4] .. repeatJobId)
rcall("XADD", ARGV[4] .. "events", "*", "event", "removed", "jobId", repeatJobId, "prev", "delayed");
rcall("XADD", KEYS[3], "*", "event", "removed", "jobId", repeatJobId, "prev", "delayed")
end
end

if(rcall("ZREM", KEYS[1], ARGV[3]) == 1) then
rcall("DEL", KEYS[1] .. ":" .. ARGV[3])
return 0
end

Expand Down
11 changes: 10 additions & 1 deletion tests/test_repeat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1215,6 +1215,7 @@ describe('repeat', function () {
});

it('should be able to remove repeatable jobs by key', async () => {
const client = await queue.client;
const repeat = { pattern: '*/2 * * * * *' };

const createdJob = await queue.add('remove', { foo: 'bar' }, { repeat });
Expand All @@ -1223,9 +1224,17 @@ describe('repeat', function () {
const job = await queue.getJob(createdJob.id!);
const repeatableJobs = await queue.getRepeatableJobs();
expect(repeatableJobs).to.have.length(1);
const removed = await queue.removeRepeatableByKey(createdJob.repeatJobKey);
const existBeforeRemoval = await client.exists(
`${prefix}:${queue.name}:repeat:${createdJob.repeatJobKey!}`,
);
expect(existBeforeRemoval).to.be.equal(1);
const removed = await queue.removeRepeatableByKey(createdJob.repeatJobKey!);
const delayedCount = await queue.getJobCountByTypes('delayed');
expect(delayedCount).to.be.equal(0);
const existAfterRemoval = await client.exists(
`${prefix}:${queue.name}:repeat:${createdJob.repeatJobKey!}`,
);
expect(existAfterRemoval).to.be.equal(0);
expect(job!.repeatJobKey).to.not.be.undefined;
expect(removed).to.be.true;
const repeatableJobsAfterRemove = await queue.getRepeatableJobs();
Expand Down

0 comments on commit 97a297d

Please sign in to comment.