bullmq 4.17.0 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/classes/flow-producer.js +3 -10
- package/dist/cjs/classes/flow-producer.js.map +1 -1
- package/dist/cjs/classes/job.js +21 -11
- package/dist/cjs/classes/job.js.map +1 -1
- package/dist/cjs/classes/queue-base.js +2 -9
- package/dist/cjs/classes/queue-base.js.map +1 -1
- package/dist/cjs/classes/queue-events.js +3 -1
- package/dist/cjs/classes/queue-events.js.map +1 -1
- package/dist/cjs/classes/queue-keys.js +1 -0
- package/dist/cjs/classes/queue-keys.js.map +1 -1
- package/dist/cjs/classes/redis-connection.js +9 -7
- package/dist/cjs/classes/redis-connection.js.map +1 -1
- package/dist/cjs/classes/scripts.js +34 -34
- package/dist/cjs/classes/scripts.js.map +1 -1
- package/dist/cjs/classes/worker.js +27 -32
- package/dist/cjs/classes/worker.js.map +1 -1
- package/dist/cjs/commands/{addDelayedJob-7.lua → addDelayedJob-6.lua} +18 -22
- package/dist/cjs/commands/addParentJob-4.lua +0 -2
- package/dist/{esm/commands/addPrioritizedJob-8.lua → cjs/commands/addPrioritizedJob-7.lua} +18 -24
- package/dist/cjs/commands/{addStandardJob-6.lua → addStandardJob-7.lua} +6 -2
- package/dist/cjs/commands/changePriority-6.lua +57 -0
- package/dist/cjs/commands/getCounts-1.lua +1 -0
- package/dist/cjs/commands/getRanges-1.lua +1 -0
- package/dist/cjs/commands/includes/addDelayMarkerIfNeeded.lua +5 -19
- package/dist/cjs/commands/includes/addJobWithPriority.lua +3 -7
- package/dist/cjs/commands/includes/checkStalledJobs.lua +1 -1
- package/dist/cjs/commands/includes/isQueuePaused.lua +7 -0
- package/dist/cjs/commands/includes/moveParentToWaitIfNeeded.lua +39 -30
- package/dist/cjs/commands/includes/prepareJobForProcessing.lua +1 -1
- package/dist/cjs/commands/includes/promoteDelayedJobs.lua +7 -4
- package/dist/{esm/commands/moveToActive-10.lua → cjs/commands/moveToActive-11.lua} +18 -29
- package/dist/cjs/commands/moveToDelayed-7.lua +77 -0
- package/dist/cjs/commands/{moveToFinished-13.lua → moveToFinished-14.lua} +29 -22
- package/dist/cjs/commands/moveToWaitingChildren-4.lua +7 -4
- package/dist/cjs/commands/pause-7.lua +41 -0
- package/dist/cjs/commands/promote-8.lua +60 -0
- package/dist/cjs/commands/{retryJob-9.lua → retryJob-10.lua} +16 -11
- package/dist/cjs/scripts/{addDelayedJob-7.js → addDelayedJob-6.js} +77 -88
- package/dist/cjs/scripts/{moveToActive-10.js.map → addDelayedJob-6.js.map} +1 -1
- package/dist/cjs/scripts/addParentJob-4.js +51 -61
- package/dist/cjs/scripts/addParentJob-4.js.map +1 -1
- package/dist/cjs/scripts/{addPrioritizedJob-8.js → addPrioritizedJob-7.js} +80 -93
- package/dist/cjs/scripts/addPrioritizedJob-7.js.map +1 -0
- package/dist/cjs/scripts/{addStandardJob-6.js → addStandardJob-7.js} +58 -63
- package/dist/cjs/scripts/addStandardJob-7.js.map +1 -0
- package/dist/cjs/scripts/changePriority-6.js +85 -0
- package/dist/cjs/scripts/changePriority-6.js.map +1 -0
- package/dist/cjs/scripts/getCounts-1.js +1 -0
- package/dist/cjs/scripts/getCounts-1.js.map +1 -1
- package/dist/cjs/scripts/getRanges-1.js +1 -0
- package/dist/cjs/scripts/getRanges-1.js.map +1 -1
- package/dist/cjs/scripts/index.js +10 -10
- package/dist/cjs/scripts/index.js.map +1 -1
- package/dist/cjs/scripts/moveStalledJobsToWait-8.js +1 -0
- package/dist/cjs/scripts/moveStalledJobsToWait-8.js.map +1 -1
- package/dist/cjs/scripts/{moveToActive-10.js → moveToActive-11.js} +30 -48
- package/dist/cjs/scripts/moveToActive-11.js.map +1 -0
- package/dist/cjs/scripts/moveToDelayed-7.js +103 -0
- package/dist/cjs/scripts/moveToDelayed-7.js.map +1 -0
- package/dist/cjs/scripts/{moveToFinished-13.js → moveToFinished-14.js} +89 -88
- package/dist/cjs/scripts/{moveToFinished-13.js.map → moveToFinished-14.js.map} +1 -1
- package/dist/cjs/scripts/moveToWaitingChildren-4.js +6 -3
- package/dist/cjs/scripts/moveToWaitingChildren-4.js.map +1 -1
- package/dist/cjs/scripts/pause-7.js +67 -0
- package/dist/cjs/scripts/pause-7.js.map +1 -0
- package/dist/cjs/scripts/promote-8.js +79 -0
- package/dist/cjs/scripts/promote-8.js.map +1 -0
- package/dist/cjs/scripts/{retryJob-9.js → retryJob-10.js} +26 -32
- package/dist/cjs/scripts/retryJob-10.js.map +1 -0
- package/dist/cjs/tsconfig-cjs.tsbuildinfo +1 -1
- package/dist/esm/classes/flow-producer.js +3 -10
- package/dist/esm/classes/flow-producer.js.map +1 -1
- package/dist/esm/classes/job.d.ts +5 -0
- package/dist/esm/classes/job.js +21 -11
- package/dist/esm/classes/job.js.map +1 -1
- package/dist/esm/classes/queue-base.js +2 -9
- package/dist/esm/classes/queue-base.js.map +1 -1
- package/dist/esm/classes/queue-events.js +3 -1
- package/dist/esm/classes/queue-events.js.map +1 -1
- package/dist/esm/classes/queue-keys.js +1 -0
- package/dist/esm/classes/queue-keys.js.map +1 -1
- package/dist/esm/classes/redis-connection.js +9 -7
- package/dist/esm/classes/redis-connection.js.map +1 -1
- package/dist/esm/classes/scripts.d.ts +4 -4
- package/dist/esm/classes/scripts.js +34 -34
- package/dist/esm/classes/scripts.js.map +1 -1
- package/dist/esm/classes/worker.d.ts +1 -1
- package/dist/esm/classes/worker.js +27 -32
- package/dist/esm/classes/worker.js.map +1 -1
- package/dist/esm/commands/{addDelayedJob-7.lua → addDelayedJob-6.lua} +18 -22
- package/dist/esm/commands/addParentJob-4.lua +0 -2
- package/dist/{cjs/commands/addPrioritizedJob-8.lua → esm/commands/addPrioritizedJob-7.lua} +18 -24
- package/dist/esm/commands/{addStandardJob-6.lua → addStandardJob-7.lua} +6 -2
- package/dist/esm/commands/changePriority-6.lua +57 -0
- package/dist/esm/commands/getCounts-1.lua +1 -0
- package/dist/esm/commands/getRanges-1.lua +1 -0
- package/dist/esm/commands/includes/addDelayMarkerIfNeeded.lua +5 -19
- package/dist/esm/commands/includes/addJobWithPriority.lua +3 -7
- package/dist/esm/commands/includes/checkStalledJobs.lua +1 -1
- package/dist/esm/commands/includes/isQueuePaused.lua +7 -0
- package/dist/esm/commands/includes/moveParentToWaitIfNeeded.lua +39 -30
- package/dist/esm/commands/includes/prepareJobForProcessing.lua +1 -1
- package/dist/esm/commands/includes/promoteDelayedJobs.lua +7 -4
- package/dist/{cjs/commands/moveToActive-10.lua → esm/commands/moveToActive-11.lua} +18 -29
- package/dist/esm/commands/moveToDelayed-7.lua +77 -0
- package/dist/esm/commands/{moveToFinished-13.lua → moveToFinished-14.lua} +29 -22
- package/dist/esm/commands/moveToWaitingChildren-4.lua +7 -4
- package/dist/esm/commands/pause-7.lua +41 -0
- package/dist/esm/commands/promote-8.lua +60 -0
- package/dist/esm/commands/{retryJob-9.lua → retryJob-10.lua} +16 -11
- package/dist/esm/interfaces/job-json.d.ts +4 -1
- package/dist/esm/interfaces/minimal-job.d.ts +3 -0
- package/dist/esm/interfaces/queue-options.d.ts +1 -1
- package/dist/esm/scripts/{addDelayedJob-7.js → addDelayedJob-6.js} +77 -88
- package/dist/esm/scripts/{moveToActive-10.js.map → addDelayedJob-6.js.map} +1 -1
- package/dist/esm/scripts/addParentJob-4.js +51 -61
- package/dist/esm/scripts/addParentJob-4.js.map +1 -1
- package/dist/esm/scripts/{addPrioritizedJob-8.js → addPrioritizedJob-7.js} +80 -93
- package/dist/esm/scripts/addPrioritizedJob-7.js.map +1 -0
- package/dist/esm/scripts/{addStandardJob-6.js → addStandardJob-7.js} +58 -63
- package/dist/esm/scripts/addStandardJob-7.js.map +1 -0
- package/dist/esm/scripts/changePriority-6.js +82 -0
- package/dist/esm/scripts/changePriority-6.js.map +1 -0
- package/dist/esm/scripts/getCounts-1.js +1 -0
- package/dist/esm/scripts/getCounts-1.js.map +1 -1
- package/dist/esm/scripts/getRanges-1.js +1 -0
- package/dist/esm/scripts/getRanges-1.js.map +1 -1
- package/dist/esm/scripts/index.d.ts +10 -10
- package/dist/esm/scripts/index.js +10 -10
- package/dist/esm/scripts/index.js.map +1 -1
- package/dist/esm/scripts/moveStalledJobsToWait-8.js +1 -0
- package/dist/esm/scripts/moveStalledJobsToWait-8.js.map +1 -1
- package/dist/esm/scripts/{moveToActive-10.js → moveToActive-11.js} +30 -48
- package/dist/esm/scripts/moveToActive-11.js.map +1 -0
- package/dist/esm/scripts/moveToDelayed-7.js +100 -0
- package/dist/esm/scripts/moveToDelayed-7.js.map +1 -0
- package/dist/esm/scripts/{moveToFinished-13.js → moveToFinished-14.js} +89 -88
- package/dist/esm/scripts/{moveToFinished-13.js.map → moveToFinished-14.js.map} +1 -1
- package/dist/esm/scripts/moveToWaitingChildren-4.js +6 -3
- package/dist/esm/scripts/moveToWaitingChildren-4.js.map +1 -1
- package/dist/esm/scripts/pause-7.js +64 -0
- package/dist/esm/scripts/pause-7.js.map +1 -0
- package/dist/esm/scripts/promote-8.js +76 -0
- package/dist/esm/scripts/promote-8.js.map +1 -0
- package/dist/esm/scripts/{retryJob-9.js → retryJob-10.js} +26 -32
- package/dist/esm/scripts/retryJob-10.js.map +1 -0
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/dist/cjs/commands/changePriority-5.lua +0 -52
- package/dist/cjs/commands/includes/addPriorityMarkerIfNeeded.lua +0 -12
- package/dist/cjs/commands/moveToDelayed-8.lua +0 -72
- package/dist/cjs/commands/pause-5.lua +0 -36
- package/dist/cjs/commands/promote-7.lua +0 -57
- package/dist/cjs/scripts/addDelayedJob-7.js.map +0 -1
- package/dist/cjs/scripts/addPrioritizedJob-8.js.map +0 -1
- package/dist/cjs/scripts/addStandardJob-6.js.map +0 -1
- package/dist/cjs/scripts/changePriority-5.js +0 -87
- package/dist/cjs/scripts/changePriority-5.js.map +0 -1
- package/dist/cjs/scripts/moveToDelayed-8.js +0 -168
- package/dist/cjs/scripts/moveToDelayed-8.js.map +0 -1
- package/dist/cjs/scripts/pause-5.js +0 -48
- package/dist/cjs/scripts/pause-5.js.map +0 -1
- package/dist/cjs/scripts/promote-7.js +0 -87
- package/dist/cjs/scripts/promote-7.js.map +0 -1
- package/dist/cjs/scripts/retryJob-9.js.map +0 -1
- package/dist/esm/commands/changePriority-5.lua +0 -52
- package/dist/esm/commands/includes/addPriorityMarkerIfNeeded.lua +0 -12
- package/dist/esm/commands/moveToDelayed-8.lua +0 -72
- package/dist/esm/commands/pause-5.lua +0 -36
- package/dist/esm/commands/promote-7.lua +0 -57
- package/dist/esm/scripts/addDelayedJob-7.js.map +0 -1
- package/dist/esm/scripts/addPrioritizedJob-8.js.map +0 -1
- package/dist/esm/scripts/addStandardJob-6.js.map +0 -1
- package/dist/esm/scripts/changePriority-5.js +0 -84
- package/dist/esm/scripts/changePriority-5.js.map +0 -1
- package/dist/esm/scripts/moveToDelayed-8.js +0 -165
- package/dist/esm/scripts/moveToDelayed-8.js.map +0 -1
- package/dist/esm/scripts/pause-5.js +0 -45
- package/dist/esm/scripts/pause-5.js.map +0 -1
- package/dist/esm/scripts/promote-7.js +0 -84
- package/dist/esm/scripts/promote-7.js.map +0 -1
- package/dist/esm/scripts/retryJob-9.js.map +0 -1
- /package/dist/esm/scripts/{addDelayedJob-7.d.ts → addDelayedJob-6.d.ts} +0 -0
- /package/dist/esm/scripts/{addPrioritizedJob-8.d.ts → addPrioritizedJob-7.d.ts} +0 -0
- /package/dist/esm/scripts/{addStandardJob-6.d.ts → addStandardJob-7.d.ts} +0 -0
- /package/dist/esm/scripts/{changePriority-5.d.ts → changePriority-6.d.ts} +0 -0
- /package/dist/esm/scripts/{moveToActive-10.d.ts → moveToActive-11.d.ts} +0 -0
- /package/dist/esm/scripts/{moveToDelayed-8.d.ts → moveToDelayed-7.d.ts} +0 -0
- /package/dist/esm/scripts/{moveToFinished-13.d.ts → moveToFinished-14.d.ts} +0 -0
- /package/dist/esm/scripts/{pause-5.d.ts → pause-7.d.ts} +0 -0
- /package/dist/esm/scripts/{promote-7.d.ts → promote-8.d.ts} +0 -0
- /package/dist/esm/scripts/{retryJob-9.d.ts → retryJob-10.d.ts} +0 -0
@@ -19,6 +19,7 @@ const content = `--[[
|
|
19
19
|
KEYS[4] 'id'
|
20
20
|
KEYS[5] 'completed'
|
21
21
|
KEYS[6] events stream key
|
22
|
+
KEYS[7] marker key
|
22
23
|
ARGV[1] msgpacked arguments array
|
23
24
|
[1] key prefix,
|
24
25
|
[2] custom id (will not generate one automatically)
|
@@ -82,7 +83,7 @@ end
|
|
82
83
|
-- Includes
|
83
84
|
--[[
|
84
85
|
Add delay marker if needed.
|
85
|
-
]]
|
86
|
+
]]
|
86
87
|
-- Includes
|
87
88
|
--[[
|
88
89
|
Function to return the next delayed job timestamp.
|
@@ -97,47 +98,30 @@ local function getNextDelayedTimestamp(delayedKey)
|
|
97
98
|
return nextTimestamp
|
98
99
|
end
|
99
100
|
end
|
100
|
-
local function addDelayMarkerIfNeeded(
|
101
|
-
local waitLen = rcall("LLEN", targetKey)
|
102
|
-
if waitLen <= 1 then
|
101
|
+
local function addDelayMarkerIfNeeded(markerKey, delayedKey)
|
103
102
|
local nextTimestamp = getNextDelayedTimestamp(delayedKey)
|
104
103
|
if nextTimestamp ~= nil then
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
local marker = rcall("LINDEX", targetKey, 0)
|
109
|
-
local oldTimestamp = tonumber(marker:sub(3))
|
110
|
-
if oldTimestamp and oldTimestamp > nextTimestamp then
|
111
|
-
rcall("LSET", targetKey, 0, "0:" .. nextTimestamp)
|
112
|
-
end
|
113
|
-
else
|
114
|
-
-- if there is no marker, then we need to add one
|
115
|
-
rcall("LPUSH", targetKey, "0:" .. nextTimestamp)
|
116
|
-
end
|
104
|
+
-- Replace the score of the marker with the newest known
|
105
|
+
-- next timestamp.
|
106
|
+
rcall("ZADD", markerKey, nextTimestamp, "0")
|
117
107
|
end
|
118
|
-
end
|
119
108
|
end
|
120
109
|
--[[
|
121
|
-
Function to
|
110
|
+
Function to check for the meta.paused key to decide if we are paused or not
|
111
|
+
(since an empty list and !EXISTS are not really the same).
|
122
112
|
]]
|
123
|
-
|
113
|
+
local function isQueuePaused(queueMetaKey)
|
114
|
+
return rcall("HEXISTS", queueMetaKey, "paused") == 1
|
115
|
+
end
|
124
116
|
--[[
|
125
|
-
Function
|
126
|
-
in order to wake up our workers and to respect priority
|
127
|
-
order as much as possible
|
117
|
+
Function to add job considering priority.
|
128
118
|
]]
|
129
|
-
local function
|
130
|
-
local waitLen = rcall("LLEN", waitKey)
|
131
|
-
if waitLen == 0 then
|
132
|
-
rcall("LPUSH", waitKey, "0:0")
|
133
|
-
end
|
134
|
-
end
|
135
|
-
local function addJobWithPriority(waitKey, prioritizedKey, priority, paused, jobId, priorityCounterKey)
|
119
|
+
local function addJobWithPriority(markerKey, prioritizedKey, priority, jobId, priorityCounterKey, isPaused)
|
136
120
|
local prioCounter = rcall("INCR", priorityCounterKey)
|
137
121
|
local score = priority * 0x100000000 + bit.band(prioCounter, 0xffffffffffff)
|
138
122
|
rcall("ZADD", prioritizedKey, score, jobId)
|
139
|
-
if not
|
140
|
-
|
123
|
+
if not isPaused then
|
124
|
+
rcall("ZADD", markerKey, 0, "0")
|
141
125
|
end
|
142
126
|
end
|
143
127
|
--[[
|
@@ -151,35 +135,44 @@ local function getTargetQueueList(queueMetaKey, waitKey, pausedKey)
|
|
151
135
|
return pausedKey, true
|
152
136
|
end
|
153
137
|
end
|
154
|
-
local function moveParentToWaitIfNeeded(parentQueueKey, parentDependenciesKey,
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
138
|
+
local function moveParentToWaitIfNeeded(parentQueueKey, parentDependenciesKey,
|
139
|
+
parentKey, parentId, timestamp)
|
140
|
+
local isParentActive = rcall("ZSCORE",
|
141
|
+
parentQueueKey .. ":waiting-children", parentId)
|
142
|
+
if rcall("SCARD", parentDependenciesKey) == 0 and isParentActive then
|
143
|
+
rcall("ZREM", parentQueueKey .. ":waiting-children", parentId)
|
144
|
+
local parentWaitKey = parentQueueKey .. ":wait"
|
145
|
+
local parentPausedKey = parentQueueKey .. ":paused"
|
146
|
+
local parentMetaKey = parentQueueKey .. ":meta"
|
147
|
+
local parentMarkerKey = parentQueueKey .. ":marker"
|
148
|
+
local jobAttributes = rcall("HMGET", parentKey, "priority", "delay")
|
149
|
+
local priority = tonumber(jobAttributes[1]) or 0
|
150
|
+
local delay = tonumber(jobAttributes[2]) or 0
|
151
|
+
if delay > 0 then
|
152
|
+
local delayedTimestamp = tonumber(timestamp) + delay
|
153
|
+
local score = delayedTimestamp * 0x1000
|
154
|
+
local parentDelayedKey = parentQueueKey .. ":delayed"
|
155
|
+
rcall("ZADD", parentDelayedKey, score, parentId)
|
156
|
+
rcall("XADD", parentQueueKey .. ":events", "*", "event", "delayed",
|
157
|
+
"jobId", parentId, "delay", delayedTimestamp)
|
158
|
+
addDelayMarkerIfNeeded(parentMarkerKey, parentDelayedKey)
|
159
|
+
else
|
160
|
+
if priority == 0 then
|
161
|
+
local parentTarget, _paused =
|
162
|
+
getTargetQueueList(parentMetaKey, parentWaitKey,
|
163
|
+
parentPausedKey)
|
164
|
+
rcall("RPUSH", parentTarget, parentId)
|
165
|
+
rcall("ZADD", parentMarkerKey, 0, "0")
|
166
|
+
else
|
167
|
+
local isPaused = isQueuePaused(parentMetaKey)
|
168
|
+
addJobWithPriority(parentMarkerKey,
|
169
|
+
parentQueueKey .. ":prioritized", priority,
|
170
|
+
parentId, parentQueueKey .. ":pc", isPaused)
|
171
|
+
end
|
172
|
+
rcall("XADD", parentQueueKey .. ":events", "*", "event", "waiting",
|
173
|
+
"jobId", parentId, "prev", "waiting-children")
|
174
|
+
end
|
181
175
|
end
|
182
|
-
end
|
183
176
|
end
|
184
177
|
local function updateParentDepsIfNeeded(parentKey, parentQueueKey, parentDependenciesKey,
|
185
178
|
parentId, jobIdKey, returnvalue, timestamp )
|
@@ -246,6 +239,10 @@ end
|
|
246
239
|
storeJob(eventsKey, jobIdKey, jobId, args[3], ARGV[2], opts, timestamp,
|
247
240
|
parentKey, parentData, repeatJobKey)
|
248
241
|
local target, paused = getTargetQueueList(metaKey, KEYS[1], KEYS[2])
|
242
|
+
if not paused then
|
243
|
+
-- mark that a job is available
|
244
|
+
rcall("ZADD", KEYS[7], 0, "0")
|
245
|
+
end
|
249
246
|
-- LIFO or FIFO
|
250
247
|
local pushCmd = opts['lifo'] and 'RPUSH' or 'LPUSH'
|
251
248
|
rcall(pushCmd, target, jobId)
|
@@ -253,8 +250,6 @@ rcall(pushCmd, target, jobId)
|
|
253
250
|
rcall("XADD", eventsKey, "MAXLEN", "~", maxEvents, "*", "event", "waiting",
|
254
251
|
"jobId", jobId)
|
255
252
|
-- Check if this job is a child of another job, if so add it to the parents dependencies
|
256
|
-
-- TODO: Should not be possible to add a child job to a parent that is not in the "waiting-children" status.
|
257
|
-
-- fail in this case.
|
258
253
|
if parentDependenciesKey ~= nil then
|
259
254
|
rcall("SADD", parentDependenciesKey, jobIdKey)
|
260
255
|
end
|
@@ -263,6 +258,6 @@ return jobId .. "" -- convert to string
|
|
263
258
|
export const addStandardJob = {
|
264
259
|
name: 'addStandardJob',
|
265
260
|
content,
|
266
|
-
keys:
|
261
|
+
keys: 7,
|
267
262
|
};
|
268
|
-
//# sourceMappingURL=addStandardJob-
|
263
|
+
//# sourceMappingURL=addStandardJob-7.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"addStandardJob-7.js","sourceRoot":"","sources":["../../../src/scripts/addStandardJob-7.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgQf,CAAC;AACF,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,IAAI,EAAE,gBAAgB;IACtB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
|
@@ -0,0 +1,82 @@
|
|
1
|
+
const content = `--[[
|
2
|
+
Change job priority
|
3
|
+
Input:
|
4
|
+
KEYS[1] 'wait',
|
5
|
+
KEYS[2] 'paused'
|
6
|
+
KEYS[3] 'meta'
|
7
|
+
KEYS[4] 'prioritized'
|
8
|
+
KEYS[5] 'pc' priority counter
|
9
|
+
KEYS[6] 'marker'
|
10
|
+
ARGV[1] priority value
|
11
|
+
ARGV[2] job key
|
12
|
+
ARGV[3] job id
|
13
|
+
ARGV[4] lifo
|
14
|
+
Output:
|
15
|
+
0 - OK
|
16
|
+
-1 - Missing job
|
17
|
+
]]
|
18
|
+
local jobKey = ARGV[2]
|
19
|
+
local jobId = ARGV[3]
|
20
|
+
local priority = tonumber(ARGV[1])
|
21
|
+
local rcall = redis.call
|
22
|
+
-- Includes
|
23
|
+
--[[
|
24
|
+
Function to check for the meta.paused key to decide if we are paused or not
|
25
|
+
(since an empty list and !EXISTS are not really the same).
|
26
|
+
]]
|
27
|
+
local function isQueuePaused(queueMetaKey)
|
28
|
+
return rcall("HEXISTS", queueMetaKey, "paused") == 1
|
29
|
+
end
|
30
|
+
--[[
|
31
|
+
Function to add job considering priority.
|
32
|
+
]]
|
33
|
+
local function addJobWithPriority(markerKey, prioritizedKey, priority, jobId, priorityCounterKey, isPaused)
|
34
|
+
local prioCounter = rcall("INCR", priorityCounterKey)
|
35
|
+
local score = priority * 0x100000000 + bit.band(prioCounter, 0xffffffffffff)
|
36
|
+
rcall("ZADD", prioritizedKey, score, jobId)
|
37
|
+
if not isPaused then
|
38
|
+
rcall("ZADD", markerKey, 0, "0")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
--[[
|
42
|
+
Function to check for the meta.paused key to decide if we are paused or not
|
43
|
+
(since an empty list and !EXISTS are not really the same).
|
44
|
+
]]
|
45
|
+
local function getTargetQueueList(queueMetaKey, waitKey, pausedKey)
|
46
|
+
if rcall("HEXISTS", queueMetaKey, "paused") ~= 1 then
|
47
|
+
return waitKey, false
|
48
|
+
else
|
49
|
+
return pausedKey, true
|
50
|
+
end
|
51
|
+
end
|
52
|
+
if rcall("EXISTS", jobKey) == 1 then
|
53
|
+
local metaKey = KEYS[3]
|
54
|
+
local isPaused = isQueuePaused(metaKey)
|
55
|
+
local markerKey = KEYS[6]
|
56
|
+
local prioritizedKey = KEYS[4]
|
57
|
+
-- Re-add with the new priority
|
58
|
+
if rcall("ZREM", KEYS[4], jobId) > 0 then
|
59
|
+
addJobWithPriority(markerKey, prioritizedKey, priority, jobId, KEYS[5],
|
60
|
+
isPaused)
|
61
|
+
-- If the new priority is 0, then just leave the job where it is in the wait list.
|
62
|
+
elseif priority > 0 then
|
63
|
+
-- Job is already in the wait list, we need to re-add it with the new priority.
|
64
|
+
local target = isPaused and KEYS[2] or KEYS[1]
|
65
|
+
local numRemovedElements = rcall("LREM", target, -1, jobId)
|
66
|
+
if numRemovedElements > 0 then
|
67
|
+
addJobWithPriority(markerKey, prioritizedKey, priority, jobId,
|
68
|
+
KEYS[5], isPaused)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
rcall("HSET", jobKey, "priority", priority)
|
72
|
+
return 0
|
73
|
+
else
|
74
|
+
return -1
|
75
|
+
end
|
76
|
+
`;
|
77
|
+
export const changePriority = {
|
78
|
+
name: 'changePriority',
|
79
|
+
content,
|
80
|
+
keys: 6,
|
81
|
+
};
|
82
|
+
//# sourceMappingURL=changePriority-6.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"changePriority-6.js","sourceRoot":"","sources":["../../../src/scripts/changePriority-6.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2Ef,CAAC;AACF,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,IAAI,EAAE,gBAAgB;IACtB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
|
@@ -10,6 +10,7 @@ local results = {}
|
|
10
10
|
for i = 1, #ARGV do
|
11
11
|
local stateKey = prefix .. ARGV[i]
|
12
12
|
if ARGV[i] == "wait" or ARGV[i] == "paused" then
|
13
|
+
-- Markers in waitlist DEPRECATED in v5: Remove in v6.
|
13
14
|
local marker = rcall("LINDEX", stateKey, -1)
|
14
15
|
if marker and string.sub(marker, 1, 2) == "0:" then
|
15
16
|
local count = rcall("LLEN", stateKey)
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"getCounts-1.js","sourceRoot":"","sources":["../../../src/scripts/getCounts-1.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG
|
1
|
+
{"version":3,"file":"getCounts-1.js","sourceRoot":"","sources":["../../../src/scripts/getCounts-1.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgCf,CAAC;AACF,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,IAAI,EAAE,WAAW;IACjB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
|
@@ -37,6 +37,7 @@ end
|
|
37
37
|
for i = 4, #ARGV do
|
38
38
|
local stateKey = prefix .. ARGV[i]
|
39
39
|
if ARGV[i] == "wait" or ARGV[i] == "paused" then
|
40
|
+
-- Markers in waitlist DEPRECATED in v5: Remove in v6.
|
40
41
|
local marker = rcall("LINDEX", stateKey, -1)
|
41
42
|
if marker and string.sub(marker, 1, 2) == "0:" then
|
42
43
|
local count = rcall("LLEN", stateKey)
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"getRanges-1.js","sourceRoot":"","sources":["../../../src/scripts/getRanges-1.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG
|
1
|
+
{"version":3,"file":"getRanges-1.js","sourceRoot":"","sources":["../../../src/scripts/getRanges-1.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+Df,CAAC;AACF,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,IAAI,EAAE,WAAW;IACjB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
|
@@ -1,9 +1,9 @@
|
|
1
|
-
export * from './addDelayedJob-
|
1
|
+
export * from './addDelayedJob-6';
|
2
2
|
export * from './addParentJob-4';
|
3
|
-
export * from './addPrioritizedJob-
|
4
|
-
export * from './addStandardJob-
|
3
|
+
export * from './addPrioritizedJob-7';
|
4
|
+
export * from './addStandardJob-7';
|
5
5
|
export * from './changeDelay-3';
|
6
|
-
export * from './changePriority-
|
6
|
+
export * from './changePriority-6';
|
7
7
|
export * from './cleanJobsInSet-2';
|
8
8
|
export * from './drain-4';
|
9
9
|
export * from './extendLock-2';
|
@@ -16,19 +16,19 @@ export * from './isJobInList-1';
|
|
16
16
|
export * from './moveJobFromActiveToWait-9';
|
17
17
|
export * from './moveJobsToWait-6';
|
18
18
|
export * from './moveStalledJobsToWait-8';
|
19
|
-
export * from './moveToActive-
|
20
|
-
export * from './moveToDelayed-
|
21
|
-
export * from './moveToFinished-
|
19
|
+
export * from './moveToActive-11';
|
20
|
+
export * from './moveToDelayed-7';
|
21
|
+
export * from './moveToFinished-14';
|
22
22
|
export * from './moveToWaitingChildren-4';
|
23
23
|
export * from './obliterate-2';
|
24
24
|
export * from './paginate-1';
|
25
|
-
export * from './pause-
|
26
|
-
export * from './promote-
|
25
|
+
export * from './pause-7';
|
26
|
+
export * from './promote-8';
|
27
27
|
export * from './releaseLock-1';
|
28
28
|
export * from './removeJob-1';
|
29
29
|
export * from './removeRepeatable-2';
|
30
30
|
export * from './reprocessJob-6';
|
31
|
-
export * from './retryJob-
|
31
|
+
export * from './retryJob-10';
|
32
32
|
export * from './saveStacktrace-1';
|
33
33
|
export * from './updateData-1';
|
34
34
|
export * from './updateProgress-3';
|
@@ -1,9 +1,9 @@
|
|
1
|
-
export * from './addDelayedJob-
|
1
|
+
export * from './addDelayedJob-6';
|
2
2
|
export * from './addParentJob-4';
|
3
|
-
export * from './addPrioritizedJob-
|
4
|
-
export * from './addStandardJob-
|
3
|
+
export * from './addPrioritizedJob-7';
|
4
|
+
export * from './addStandardJob-7';
|
5
5
|
export * from './changeDelay-3';
|
6
|
-
export * from './changePriority-
|
6
|
+
export * from './changePriority-6';
|
7
7
|
export * from './cleanJobsInSet-2';
|
8
8
|
export * from './drain-4';
|
9
9
|
export * from './extendLock-2';
|
@@ -16,19 +16,19 @@ export * from './isJobInList-1';
|
|
16
16
|
export * from './moveJobFromActiveToWait-9';
|
17
17
|
export * from './moveJobsToWait-6';
|
18
18
|
export * from './moveStalledJobsToWait-8';
|
19
|
-
export * from './moveToActive-
|
20
|
-
export * from './moveToDelayed-
|
21
|
-
export * from './moveToFinished-
|
19
|
+
export * from './moveToActive-11';
|
20
|
+
export * from './moveToDelayed-7';
|
21
|
+
export * from './moveToFinished-14';
|
22
22
|
export * from './moveToWaitingChildren-4';
|
23
23
|
export * from './obliterate-2';
|
24
24
|
export * from './paginate-1';
|
25
|
-
export * from './pause-
|
26
|
-
export * from './promote-
|
25
|
+
export * from './pause-7';
|
26
|
+
export * from './promote-8';
|
27
27
|
export * from './releaseLock-1';
|
28
28
|
export * from './removeJob-1';
|
29
29
|
export * from './removeRepeatable-2';
|
30
30
|
export * from './reprocessJob-6';
|
31
|
-
export * from './retryJob-
|
31
|
+
export * from './retryJob-10';
|
32
32
|
export * from './saveStacktrace-1';
|
33
33
|
export * from './updateData-1';
|
34
34
|
export * from './updateProgress-3';
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/scripts/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,oBAAoB,CAAC;AACnC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/scripts/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,oBAAoB,CAAC;AACnC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oBAAoB,CAAC"}
|
@@ -203,6 +203,7 @@ local function checkStalledJobs(stalledKey, waitKey, activeKey, failedKey,
|
|
203
203
|
local MAX_STALLED_JOB_COUNT = tonumber(maxStalledJobCount)
|
204
204
|
-- Remove from active list
|
205
205
|
for i, jobId in ipairs(stalling) do
|
206
|
+
-- Markers in waitlist DEPRECATED in v5: Remove in v6.
|
206
207
|
if string.sub(jobId, 1, 2) == "0:" then
|
207
208
|
-- If the jobId is a delay marker ID we just remove it.
|
208
209
|
rcall("LREM", activeKey, 1, jobId)
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"moveStalledJobsToWait-8.js","sourceRoot":"","sources":["../../../src/scripts/moveStalledJobsToWait-8.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG
|
1
|
+
{"version":3,"file":"moveStalledJobsToWait-8.js","sourceRoot":"","sources":["../../../src/scripts/moveStalledJobsToWait-8.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwRf,CAAC;AACF,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,IAAI,EAAE,uBAAuB;IAC7B,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
|
@@ -13,15 +13,16 @@ const content = `--[[
|
|
13
13
|
-- Rate limiting
|
14
14
|
KEYS[6] rate limiter key
|
15
15
|
KEYS[7] delayed key
|
16
|
-
--
|
16
|
+
-- Delayed jobs
|
17
17
|
KEYS[8] paused key
|
18
18
|
KEYS[9] meta key
|
19
19
|
KEYS[10] pc priority counter
|
20
|
+
-- Marker
|
21
|
+
KEYS[11] marker key
|
20
22
|
-- Arguments
|
21
23
|
ARGV[1] key prefix
|
22
24
|
ARGV[2] timestamp
|
23
|
-
ARGV[3]
|
24
|
-
ARGV[4] opts
|
25
|
+
ARGV[3] opts
|
25
26
|
opts - token - lock token
|
26
27
|
opts - lockDuration
|
27
28
|
opts - limiter
|
@@ -31,7 +32,7 @@ local waitKey = KEYS[1]
|
|
31
32
|
local activeKey = KEYS[2]
|
32
33
|
local rateLimiterKey = KEYS[6]
|
33
34
|
local delayedKey = KEYS[7]
|
34
|
-
local opts = cmsgpack.unpack(ARGV[
|
35
|
+
local opts = cmsgpack.unpack(ARGV[3])
|
35
36
|
-- Includes
|
36
37
|
--[[
|
37
38
|
Function to return the next delayed job timestamp.
|
@@ -142,7 +143,7 @@ local function prepareJobForProcessing(keys, keyPrefix, targetKey, jobId, proces
|
|
142
143
|
end
|
143
144
|
rcall("XADD", keys[4], "*", "event", "active", "jobId", jobId, "prev", "waiting")
|
144
145
|
rcall("HSET", jobKey, "processedOn", processedOn)
|
145
|
-
rcall("HINCRBY", jobKey, "
|
146
|
+
rcall("HINCRBY", jobKey, "ats", 1)
|
146
147
|
return {rcall("HGETALL", jobKey), jobId, 0, 0} -- get job data
|
147
148
|
end
|
148
149
|
--[[
|
@@ -155,29 +156,17 @@ end
|
|
155
156
|
--[[
|
156
157
|
Function to add job considering priority.
|
157
158
|
]]
|
158
|
-
|
159
|
-
--[[
|
160
|
-
Function priority marker to wait if needed
|
161
|
-
in order to wake up our workers and to respect priority
|
162
|
-
order as much as possible
|
163
|
-
]]
|
164
|
-
local function addPriorityMarkerIfNeeded(waitKey)
|
165
|
-
local waitLen = rcall("LLEN", waitKey)
|
166
|
-
if waitLen == 0 then
|
167
|
-
rcall("LPUSH", waitKey, "0:0")
|
168
|
-
end
|
169
|
-
end
|
170
|
-
local function addJobWithPriority(waitKey, prioritizedKey, priority, paused, jobId, priorityCounterKey)
|
159
|
+
local function addJobWithPriority(markerKey, prioritizedKey, priority, jobId, priorityCounterKey, isPaused)
|
171
160
|
local prioCounter = rcall("INCR", priorityCounterKey)
|
172
161
|
local score = priority * 0x100000000 + bit.band(prioCounter, 0xffffffffffff)
|
173
162
|
rcall("ZADD", prioritizedKey, score, jobId)
|
174
|
-
if not
|
175
|
-
|
163
|
+
if not isPaused then
|
164
|
+
rcall("ZADD", markerKey, 0, "0")
|
176
165
|
end
|
177
166
|
end
|
178
167
|
-- Try to get as much as 1000 jobs at once
|
179
|
-
local function promoteDelayedJobs(delayedKey,
|
180
|
-
eventStreamKey, prefix, timestamp,
|
168
|
+
local function promoteDelayedJobs(delayedKey, markerKey, targetKey, prioritizedKey,
|
169
|
+
eventStreamKey, prefix, timestamp, priorityCounterKey, isPaused)
|
181
170
|
local jobs = rcall("ZRANGEBYSCORE", delayedKey, 0, (timestamp + 1) * 0x1000, "LIMIT", 0, 1000)
|
182
171
|
if (#jobs > 0) then
|
183
172
|
rcall("ZREM", delayedKey, unpack(jobs))
|
@@ -188,9 +177,12 @@ local function promoteDelayedJobs(delayedKey, waitKey, targetKey, prioritizedKey
|
|
188
177
|
if priority == 0 then
|
189
178
|
-- LIFO or FIFO
|
190
179
|
rcall("LPUSH", targetKey, jobId)
|
180
|
+
if not isPaused then
|
181
|
+
rcall("ZADD", markerKey, 0, "0")
|
182
|
+
end
|
191
183
|
else
|
192
|
-
addJobWithPriority(
|
193
|
-
jobId, priorityCounterKey)
|
184
|
+
addJobWithPriority(markerKey, prioritizedKey, priority,
|
185
|
+
jobId, priorityCounterKey, isPaused)
|
194
186
|
end
|
195
187
|
-- Emit waiting event
|
196
188
|
rcall("XADD", eventStreamKey, "*", "event", "waiting", "jobId",
|
@@ -201,31 +193,21 @@ local function promoteDelayedJobs(delayedKey, waitKey, targetKey, prioritizedKey
|
|
201
193
|
end
|
202
194
|
local target, paused = getTargetQueueList(KEYS[9], waitKey, KEYS[8])
|
203
195
|
-- Check if there are delayed jobs that we can move to wait.
|
204
|
-
|
205
|
-
|
196
|
+
local markerKey = KEYS[11]
|
197
|
+
promoteDelayedJobs(delayedKey, markerKey, target, KEYS[3], KEYS[4], ARGV[1],
|
198
|
+
ARGV[2], KEYS[10], paused)
|
206
199
|
local maxJobs = tonumber(opts['limiter'] and opts['limiter']['max'])
|
207
200
|
local expireTime = getRateLimitTTL(maxJobs, rateLimiterKey)
|
208
|
-
|
209
|
-
if
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
-- Check if we are rate limited first.
|
218
|
-
if expireTime > 0 then return {0, 0, expireTime, 0} end
|
219
|
-
-- paused queue
|
220
|
-
if paused then return {0, 0, 0, 0} end
|
221
|
-
-- no job ID, try non-blocking move from wait to active
|
201
|
+
-- Check if we are rate limited first.
|
202
|
+
if expireTime > 0 then return {0, 0, expireTime, 0} end
|
203
|
+
-- paused queue
|
204
|
+
if paused then return {0, 0, 0, 0} end
|
205
|
+
-- no job ID, try non-blocking move from wait to active
|
206
|
+
local jobId = rcall("RPOPLPUSH", waitKey, activeKey)
|
207
|
+
-- Markers in waitlist DEPRECATED in v5: Will be completely removed in v6.
|
208
|
+
if jobId and string.sub(jobId, 1, 2) == "0:" then
|
209
|
+
rcall("LREM", activeKey, 1, jobId)
|
222
210
|
jobId = rcall("RPOPLPUSH", waitKey, activeKey)
|
223
|
-
-- Since it is possible that between a call to BRPOPLPUSH and moveToActive
|
224
|
-
-- another script puts a new maker in wait, we need to check again.
|
225
|
-
if jobId and string.sub(jobId, 1, 2) == "0:" then
|
226
|
-
rcall("LREM", activeKey, 1, jobId)
|
227
|
-
jobId = rcall("RPOPLPUSH", waitKey, activeKey)
|
228
|
-
end
|
229
211
|
end
|
230
212
|
if jobId then
|
231
213
|
return prepareJobForProcessing(KEYS, ARGV[1], target, jobId, ARGV[2],
|
@@ -245,6 +227,6 @@ return {0, 0, 0, 0}
|
|
245
227
|
export const moveToActive = {
|
246
228
|
name: 'moveToActive',
|
247
229
|
content,
|
248
|
-
keys:
|
230
|
+
keys: 11,
|
249
231
|
};
|
250
|
-
//# sourceMappingURL=moveToActive-
|
232
|
+
//# sourceMappingURL=moveToActive-11.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"moveToActive-11.js","sourceRoot":"","sources":["../../../src/scripts/moveToActive-11.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiOf,CAAC;AACF,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,IAAI,EAAE,cAAc;IACpB,OAAO;IACP,IAAI,EAAE,EAAE;CACT,CAAC"}
|
@@ -0,0 +1,100 @@
|
|
1
|
+
const content = `--[[
|
2
|
+
Moves job from active to delayed set.
|
3
|
+
Input:
|
4
|
+
KEYS[1] marker key
|
5
|
+
KEYS[2] active key
|
6
|
+
KEYS[3] prioritized key
|
7
|
+
KEYS[4] delayed key
|
8
|
+
KEYS[5] job key
|
9
|
+
KEYS[6] events stream
|
10
|
+
KEYS[7] meta key
|
11
|
+
ARGV[1] key prefix
|
12
|
+
ARGV[2] timestamp
|
13
|
+
ARGV[3] delayedTimestamp
|
14
|
+
ARGV[4] the id of the job
|
15
|
+
ARGV[5] queue token
|
16
|
+
ARGV[6] delay value
|
17
|
+
ARGV[7] skip attempt
|
18
|
+
Output:
|
19
|
+
0 - OK
|
20
|
+
-1 - Missing job.
|
21
|
+
-3 - Job not in active set.
|
22
|
+
Events:
|
23
|
+
- delayed key.
|
24
|
+
]]
|
25
|
+
local rcall = redis.call
|
26
|
+
-- Includes
|
27
|
+
--[[
|
28
|
+
Add delay marker if needed.
|
29
|
+
]]
|
30
|
+
-- Includes
|
31
|
+
--[[
|
32
|
+
Function to return the next delayed job timestamp.
|
33
|
+
]]
|
34
|
+
local function getNextDelayedTimestamp(delayedKey)
|
35
|
+
local result = rcall("ZRANGE", delayedKey, 0, 0, "WITHSCORES")
|
36
|
+
if #result then
|
37
|
+
local nextTimestamp = tonumber(result[2])
|
38
|
+
if (nextTimestamp ~= nil) then
|
39
|
+
nextTimestamp = nextTimestamp / 0x1000
|
40
|
+
end
|
41
|
+
return nextTimestamp
|
42
|
+
end
|
43
|
+
end
|
44
|
+
local function addDelayMarkerIfNeeded(markerKey, delayedKey)
|
45
|
+
local nextTimestamp = getNextDelayedTimestamp(delayedKey)
|
46
|
+
if nextTimestamp ~= nil then
|
47
|
+
-- Replace the score of the marker with the newest known
|
48
|
+
-- next timestamp.
|
49
|
+
rcall("ZADD", markerKey, nextTimestamp, "0")
|
50
|
+
end
|
51
|
+
end
|
52
|
+
--[[
|
53
|
+
Function to check for the meta.paused key to decide if we are paused or not
|
54
|
+
(since an empty list and !EXISTS are not really the same).
|
55
|
+
]]
|
56
|
+
local function isQueuePaused(queueMetaKey)
|
57
|
+
return rcall("HEXISTS", queueMetaKey, "paused") == 1
|
58
|
+
end
|
59
|
+
local jobKey = KEYS[5]
|
60
|
+
local metaKey = KEYS[7]
|
61
|
+
if rcall("EXISTS", jobKey) == 1 then
|
62
|
+
local delayedKey = KEYS[4]
|
63
|
+
if ARGV[5] ~= "0" then
|
64
|
+
local lockKey = jobKey .. ':lock'
|
65
|
+
if rcall("GET", lockKey) == ARGV[5] then
|
66
|
+
rcall("DEL", lockKey)
|
67
|
+
else
|
68
|
+
return -2
|
69
|
+
end
|
70
|
+
end
|
71
|
+
local jobId = ARGV[4]
|
72
|
+
local score = tonumber(ARGV[3])
|
73
|
+
local delayedTimestamp = (score / 0x1000)
|
74
|
+
local numRemovedElements = rcall("LREM", KEYS[2], -1, jobId)
|
75
|
+
if numRemovedElements < 1 then return -3 end
|
76
|
+
if ARGV[7] == "0" then
|
77
|
+
rcall("HINCRBY", jobKey, "atm", 1)
|
78
|
+
end
|
79
|
+
rcall("HSET", jobKey, "delay", ARGV[6])
|
80
|
+
local maxEvents = rcall("HGET", metaKey, "opts.maxLenEvents") or 10000
|
81
|
+
rcall("ZADD", delayedKey, score, jobId)
|
82
|
+
rcall("XADD", KEYS[6], "MAXLEN", "~", maxEvents, "*", "event", "delayed",
|
83
|
+
"jobId", jobId, "delay", delayedTimestamp)
|
84
|
+
-- Check if we need to push a marker job to wake up sleeping workers.
|
85
|
+
local isPaused = isQueuePaused(metaKey)
|
86
|
+
if not isPaused then
|
87
|
+
local markerKey = KEYS[1]
|
88
|
+
addDelayMarkerIfNeeded(markerKey, delayedKey)
|
89
|
+
end
|
90
|
+
return 0
|
91
|
+
else
|
92
|
+
return -1
|
93
|
+
end
|
94
|
+
`;
|
95
|
+
export const moveToDelayed = {
|
96
|
+
name: 'moveToDelayed',
|
97
|
+
content,
|
98
|
+
keys: 7,
|
99
|
+
};
|
100
|
+
//# sourceMappingURL=moveToDelayed-7.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"moveToDelayed-7.js","sourceRoot":"","sources":["../../../src/scripts/moveToDelayed-7.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6Ff,CAAC;AACF,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,IAAI,EAAE,eAAe;IACrB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
|