From 9d8f874b959e09662985f38c4614b95ab4d5e89c Mon Sep 17 00:00:00 2001 From: Rogger Valverde Date: Wed, 17 Jul 2024 20:10:02 -0600 Subject: [PATCH] fix(repeatable): pass custom key as an args in addRepeatableJob to prevent CROSSSLOT issue (#2662) fixes #2660 --- src/classes/scripts.ts | 6 ++---- .../{addRepeatableJob-2.lua => addRepeatableJob-1.lua} | 10 +++++----- 2 files changed, 7 insertions(+), 9 deletions(-) rename src/commands/{addRepeatableJob-2.lua => addRepeatableJob-1.lua} (94%) diff --git a/src/classes/scripts.ts b/src/classes/scripts.ts index 25e8fadac7..aa608fb609 100644 --- a/src/classes/scripts.ts +++ b/src/classes/scripts.ts @@ -267,15 +267,13 @@ export class Scripts { legacyCustomKey: string, skipCheckExists: boolean, ): (string | number | Buffer)[] { - const keys: (string | number | Buffer)[] = [ - this.queue.keys.repeat, - customKey, - ]; + const keys: (string | number | Buffer)[] = [this.queue.keys.repeat]; const args = [ nextMillis, pack(opts), legacyCustomKey, + customKey, skipCheckExists ? '1' : '0', ]; diff --git a/src/commands/addRepeatableJob-2.lua b/src/commands/addRepeatableJob-1.lua similarity index 94% rename from src/commands/addRepeatableJob-2.lua rename to src/commands/addRepeatableJob-1.lua index d97126e997..6d532155eb 100644 --- a/src/commands/addRepeatableJob-2.lua +++ b/src/commands/addRepeatableJob-1.lua @@ -3,7 +3,6 @@ Input: KEYS[1] 'repeat' key - KEYS[2] custom key ARGV[1] next milliseconds ARGV[2] msgpacked options @@ -13,16 +12,17 @@ [4] endDate? [5] every? ARGV[3] legacy custom key TODO: remove this logic in next breaking change - ARGV[4] skipCheckExists + ARGV[4] custom key + ARGV[5] skipCheckExists Output: repeatableKey - OK ]] local rcall = redis.call local repeatKey = KEYS[1] -local customKey = KEYS[2] -local legacyCustomKey = ARGV[3] local nextMilli = ARGV[1] +local legacyCustomKey = ARGV[3] +local customKey = ARGV[4] local function storeRepeatableJob(repeatKey, customKey, nextMilli, rawOpts) rcall("ZADD", repeatKey, nextMilli, customKey) @@ -55,7 +55,7 @@ local function storeRepeatableJob(repeatKey, customKey, nextMilli, rawOpts) return customKey end -if ARGV[4] == '0' then +if ARGV[5] == '0' then if rcall("ZSCORE", repeatKey, legacyCustomKey) ~= false then rcall("ZADD", repeatKey, nextMilli, legacyCustomKey) return legacyCustomKey