mirror of
https://github.com/OptimalBits/bull.git
synced 2026-07-02 08:27:43 +08:00
17 lines
451 B
Lua
17 lines
451 B
Lua
--[[
|
|
Function to add job considering priority.
|
|
]]
|
|
|
|
local function addJobWithPriority(priorityKey, priority, jobId, targetKey)
|
|
rcall("ZADD", priorityKey, priority, jobId)
|
|
local count = rcall("ZCOUNT", priorityKey, 0, priority)
|
|
|
|
local len = rcall("LLEN", targetKey)
|
|
local id = rcall("LINDEX", targetKey, len - (count - 1))
|
|
if id then
|
|
rcall("LINSERT", targetKey, "BEFORE", id, jobId)
|
|
else
|
|
rcall("RPUSH", targetKey, jobId)
|
|
end
|
|
end
|