From 97a297d90ad8b27bcddb7db6a8a158acfb549389 Mon Sep 17 00:00:00 2001 From: Rogger Valverde Date: Thu, 25 Jul 2024 21:09:26 -0600 Subject: [PATCH] fix(repeatable): remove repeat hash when removing repeatable job (#2676) --- src/classes/scripts.ts | 2 +- ...{removeRepeatable-2.lua => removeRepeatable-3.lua} | 6 ++++-- tests/test_repeat.ts | 11 ++++++++++- 3 files changed, 15 insertions(+), 4 deletions(-) rename src/commands/{removeRepeatable-2.lua => removeRepeatable-3.lua} (80%) diff --git a/src/classes/scripts.ts b/src/classes/scripts.ts index 771b1d6769..ec66c5a366 100644 --- a/src/classes/scripts.ts +++ b/src/classes/scripts.ts @@ -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, diff --git a/src/commands/removeRepeatable-2.lua b/src/commands/removeRepeatable-3.lua similarity index 80% rename from src/commands/removeRepeatable-2.lua rename to src/commands/removeRepeatable-3.lua index 05a0bd21d8..34f8ce0814 100644 --- a/src/commands/removeRepeatable-2.lua +++ b/src/commands/removeRepeatable-3.lua @@ -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 @@ -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 @@ -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 diff --git a/tests/test_repeat.ts b/tests/test_repeat.ts index eb883e7de5..a127fb7c0c 100644 --- a/tests/test_repeat.ts +++ b/tests/test_repeat.ts @@ -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 }); @@ -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();