Skip to content

Commit

Permalink
chore: address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
roggervalf committed Dec 24, 2024
1 parent 413c03b commit 8e0214f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 23 deletions.
40 changes: 18 additions & 22 deletions src/commands/moveJobFromActiveToWait-9.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,33 +29,29 @@ local jobId = ARGV[1]
local token = ARGV[2]
local jobKey = ARGV[3]

if rcall("EXISTS", jobKey) == 1 then
local errorCode = removeLock(jobKey, KEYS[3], token, jobId)
if errorCode < 0 then
return errorCode
end
local errorCode = removeLock(jobKey, KEYS[3], token, jobId)
if errorCode < 0 then
return errorCode
end

local metaKey = KEYS[5]
local removed = rcall("LREM", KEYS[1], 1, jobId)
if removed > 0 then
local target, isPausedOrMaxed = getTargetQueueList(metaKey, KEYS[1], KEYS[2], KEYS[4])
local metaKey = KEYS[5]
local removed = rcall("LREM", KEYS[1], 1, jobId)
if removed > 0 then
local target, isPausedOrMaxed = getTargetQueueList(metaKey, KEYS[1], KEYS[2], KEYS[4])

local priority = tonumber(rcall("HGET", ARGV[3], "priority")) or 0
local priority = tonumber(rcall("HGET", ARGV[3], "priority")) or 0

if priority > 0 then
pushBackJobWithPriority(KEYS[7], priority, jobId)
else
addJobInTargetList(target, KEYS[8], "RPUSH", isPausedOrMaxed, jobId)
end
if priority > 0 then
pushBackJobWithPriority(KEYS[7], priority, jobId)
else
addJobInTargetList(target, KEYS[8], "RPUSH", isPausedOrMaxed, jobId)
end

local maxEvents = getOrSetMaxEvents(metaKey)
local maxEvents = getOrSetMaxEvents(metaKey)

-- Emit waiting event
rcall("XADD", KEYS[9], "MAXLEN", "~", maxEvents, "*", "event", "waiting",
"jobId", jobId)
end
else
return -1
-- Emit waiting event
rcall("XADD", KEYS[9], "MAXLEN", "~", maxEvents, "*", "event", "waiting",
"jobId", jobId)
end

local pttl = rcall("PTTL", KEYS[6])
Expand Down
2 changes: 1 addition & 1 deletion tests/test_rate_limiter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ describe('Rate Limiter', function () {
const failing = new Promise<void>(resolve => {
worker.on('error', err => {
expect(err.message).to.be.equal(
`Missing key for job ${job.id}. moveJobFromActiveToWait`,
`Missing lock for job ${job.id}. moveJobFromActiveToWait`,
);
resolve();
});
Expand Down

0 comments on commit 8e0214f

Please sign in to comment.