bullmq 4.16.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.
Files changed (192) hide show
  1. package/dist/cjs/classes/flow-producer.js +3 -10
  2. package/dist/cjs/classes/flow-producer.js.map +1 -1
  3. package/dist/cjs/classes/job.js +21 -11
  4. package/dist/cjs/classes/job.js.map +1 -1
  5. package/dist/cjs/classes/queue-base.js +2 -9
  6. package/dist/cjs/classes/queue-base.js.map +1 -1
  7. package/dist/cjs/classes/queue-events.js +3 -1
  8. package/dist/cjs/classes/queue-events.js.map +1 -1
  9. package/dist/cjs/classes/queue-keys.js +1 -0
  10. package/dist/cjs/classes/queue-keys.js.map +1 -1
  11. package/dist/cjs/classes/redis-connection.js +9 -7
  12. package/dist/cjs/classes/redis-connection.js.map +1 -1
  13. package/dist/cjs/classes/scripts.js +34 -34
  14. package/dist/cjs/classes/scripts.js.map +1 -1
  15. package/dist/cjs/classes/worker.js +41 -37
  16. package/dist/cjs/classes/worker.js.map +1 -1
  17. package/dist/cjs/commands/{addDelayedJob-7.lua → addDelayedJob-6.lua} +18 -22
  18. package/dist/cjs/commands/addParentJob-4.lua +0 -2
  19. package/dist/{esm/commands/addPrioritizedJob-8.lua → cjs/commands/addPrioritizedJob-7.lua} +18 -24
  20. package/dist/cjs/commands/{addStandardJob-6.lua → addStandardJob-7.lua} +6 -2
  21. package/dist/cjs/commands/changePriority-6.lua +57 -0
  22. package/dist/cjs/commands/getCounts-1.lua +1 -0
  23. package/dist/cjs/commands/getRanges-1.lua +1 -0
  24. package/dist/cjs/commands/includes/addDelayMarkerIfNeeded.lua +5 -19
  25. package/dist/cjs/commands/includes/addJobWithPriority.lua +3 -7
  26. package/dist/cjs/commands/includes/checkStalledJobs.lua +1 -1
  27. package/dist/cjs/commands/includes/isQueuePaused.lua +7 -0
  28. package/dist/cjs/commands/includes/moveParentToWaitIfNeeded.lua +39 -30
  29. package/dist/cjs/commands/includes/prepareJobForProcessing.lua +1 -1
  30. package/dist/cjs/commands/includes/promoteDelayedJobs.lua +7 -4
  31. package/dist/{esm/commands/moveToActive-10.lua → cjs/commands/moveToActive-11.lua} +18 -29
  32. package/dist/cjs/commands/moveToDelayed-7.lua +77 -0
  33. package/dist/cjs/commands/{moveToFinished-13.lua → moveToFinished-14.lua} +29 -22
  34. package/dist/cjs/commands/moveToWaitingChildren-4.lua +7 -4
  35. package/dist/cjs/commands/pause-7.lua +41 -0
  36. package/dist/cjs/commands/promote-8.lua +60 -0
  37. package/dist/cjs/commands/{retryJob-9.lua → retryJob-10.lua} +16 -11
  38. package/dist/cjs/scripts/{addDelayedJob-7.js → addDelayedJob-6.js} +77 -88
  39. package/dist/cjs/scripts/{moveToActive-10.js.map → addDelayedJob-6.js.map} +1 -1
  40. package/dist/cjs/scripts/addParentJob-4.js +51 -61
  41. package/dist/cjs/scripts/addParentJob-4.js.map +1 -1
  42. package/dist/cjs/scripts/{addPrioritizedJob-8.js → addPrioritizedJob-7.js} +80 -93
  43. package/dist/cjs/scripts/addPrioritizedJob-7.js.map +1 -0
  44. package/dist/cjs/scripts/{addStandardJob-6.js → addStandardJob-7.js} +58 -63
  45. package/dist/cjs/scripts/addStandardJob-7.js.map +1 -0
  46. package/dist/cjs/scripts/changePriority-6.js +85 -0
  47. package/dist/cjs/scripts/changePriority-6.js.map +1 -0
  48. package/dist/cjs/scripts/getCounts-1.js +1 -0
  49. package/dist/cjs/scripts/getCounts-1.js.map +1 -1
  50. package/dist/cjs/scripts/getRanges-1.js +1 -0
  51. package/dist/cjs/scripts/getRanges-1.js.map +1 -1
  52. package/dist/cjs/scripts/index.js +10 -10
  53. package/dist/cjs/scripts/index.js.map +1 -1
  54. package/dist/cjs/scripts/moveStalledJobsToWait-8.js +1 -0
  55. package/dist/cjs/scripts/moveStalledJobsToWait-8.js.map +1 -1
  56. package/dist/cjs/scripts/{moveToActive-10.js → moveToActive-11.js} +30 -48
  57. package/dist/cjs/scripts/moveToActive-11.js.map +1 -0
  58. package/dist/cjs/scripts/moveToDelayed-7.js +103 -0
  59. package/dist/cjs/scripts/moveToDelayed-7.js.map +1 -0
  60. package/dist/cjs/scripts/{moveToFinished-13.js → moveToFinished-14.js} +89 -88
  61. package/dist/cjs/scripts/{moveToFinished-13.js.map → moveToFinished-14.js.map} +1 -1
  62. package/dist/cjs/scripts/moveToWaitingChildren-4.js +6 -3
  63. package/dist/cjs/scripts/moveToWaitingChildren-4.js.map +1 -1
  64. package/dist/cjs/scripts/pause-7.js +67 -0
  65. package/dist/cjs/scripts/pause-7.js.map +1 -0
  66. package/dist/cjs/scripts/promote-8.js +79 -0
  67. package/dist/cjs/scripts/promote-8.js.map +1 -0
  68. package/dist/cjs/scripts/{retryJob-9.js → retryJob-10.js} +26 -32
  69. package/dist/cjs/scripts/retryJob-10.js.map +1 -0
  70. package/dist/cjs/tsconfig-cjs.tsbuildinfo +1 -1
  71. package/dist/esm/classes/flow-producer.js +3 -10
  72. package/dist/esm/classes/flow-producer.js.map +1 -1
  73. package/dist/esm/classes/job.d.ts +5 -0
  74. package/dist/esm/classes/job.js +21 -11
  75. package/dist/esm/classes/job.js.map +1 -1
  76. package/dist/esm/classes/queue-base.js +2 -9
  77. package/dist/esm/classes/queue-base.js.map +1 -1
  78. package/dist/esm/classes/queue-events.js +3 -1
  79. package/dist/esm/classes/queue-events.js.map +1 -1
  80. package/dist/esm/classes/queue-keys.js +1 -0
  81. package/dist/esm/classes/queue-keys.js.map +1 -1
  82. package/dist/esm/classes/redis-connection.js +9 -7
  83. package/dist/esm/classes/redis-connection.js.map +1 -1
  84. package/dist/esm/classes/scripts.d.ts +4 -4
  85. package/dist/esm/classes/scripts.js +34 -34
  86. package/dist/esm/classes/scripts.js.map +1 -1
  87. package/dist/esm/classes/worker.d.ts +4 -2
  88. package/dist/esm/classes/worker.js +41 -37
  89. package/dist/esm/classes/worker.js.map +1 -1
  90. package/dist/esm/commands/{addDelayedJob-7.lua → addDelayedJob-6.lua} +18 -22
  91. package/dist/esm/commands/addParentJob-4.lua +0 -2
  92. package/dist/{cjs/commands/addPrioritizedJob-8.lua → esm/commands/addPrioritizedJob-7.lua} +18 -24
  93. package/dist/esm/commands/{addStandardJob-6.lua → addStandardJob-7.lua} +6 -2
  94. package/dist/esm/commands/changePriority-6.lua +57 -0
  95. package/dist/esm/commands/getCounts-1.lua +1 -0
  96. package/dist/esm/commands/getRanges-1.lua +1 -0
  97. package/dist/esm/commands/includes/addDelayMarkerIfNeeded.lua +5 -19
  98. package/dist/esm/commands/includes/addJobWithPriority.lua +3 -7
  99. package/dist/esm/commands/includes/checkStalledJobs.lua +1 -1
  100. package/dist/esm/commands/includes/isQueuePaused.lua +7 -0
  101. package/dist/esm/commands/includes/moveParentToWaitIfNeeded.lua +39 -30
  102. package/dist/esm/commands/includes/prepareJobForProcessing.lua +1 -1
  103. package/dist/esm/commands/includes/promoteDelayedJobs.lua +7 -4
  104. package/dist/{cjs/commands/moveToActive-10.lua → esm/commands/moveToActive-11.lua} +18 -29
  105. package/dist/esm/commands/moveToDelayed-7.lua +77 -0
  106. package/dist/esm/commands/{moveToFinished-13.lua → moveToFinished-14.lua} +29 -22
  107. package/dist/esm/commands/moveToWaitingChildren-4.lua +7 -4
  108. package/dist/esm/commands/pause-7.lua +41 -0
  109. package/dist/esm/commands/promote-8.lua +60 -0
  110. package/dist/esm/commands/{retryJob-9.lua → retryJob-10.lua} +16 -11
  111. package/dist/esm/interfaces/job-json.d.ts +4 -1
  112. package/dist/esm/interfaces/minimal-job.d.ts +3 -0
  113. package/dist/esm/interfaces/queue-options.d.ts +1 -1
  114. package/dist/esm/scripts/{addDelayedJob-7.js → addDelayedJob-6.js} +77 -88
  115. package/dist/esm/scripts/{moveToActive-10.js.map → addDelayedJob-6.js.map} +1 -1
  116. package/dist/esm/scripts/addParentJob-4.js +51 -61
  117. package/dist/esm/scripts/addParentJob-4.js.map +1 -1
  118. package/dist/esm/scripts/{addPrioritizedJob-8.js → addPrioritizedJob-7.js} +80 -93
  119. package/dist/esm/scripts/addPrioritizedJob-7.js.map +1 -0
  120. package/dist/esm/scripts/{addStandardJob-6.js → addStandardJob-7.js} +58 -63
  121. package/dist/esm/scripts/addStandardJob-7.js.map +1 -0
  122. package/dist/esm/scripts/changePriority-6.js +82 -0
  123. package/dist/esm/scripts/changePriority-6.js.map +1 -0
  124. package/dist/esm/scripts/getCounts-1.js +1 -0
  125. package/dist/esm/scripts/getCounts-1.js.map +1 -1
  126. package/dist/esm/scripts/getRanges-1.js +1 -0
  127. package/dist/esm/scripts/getRanges-1.js.map +1 -1
  128. package/dist/esm/scripts/index.d.ts +10 -10
  129. package/dist/esm/scripts/index.js +10 -10
  130. package/dist/esm/scripts/index.js.map +1 -1
  131. package/dist/esm/scripts/moveStalledJobsToWait-8.js +1 -0
  132. package/dist/esm/scripts/moveStalledJobsToWait-8.js.map +1 -1
  133. package/dist/esm/scripts/{moveToActive-10.js → moveToActive-11.js} +30 -48
  134. package/dist/esm/scripts/moveToActive-11.js.map +1 -0
  135. package/dist/esm/scripts/moveToDelayed-7.js +100 -0
  136. package/dist/esm/scripts/moveToDelayed-7.js.map +1 -0
  137. package/dist/esm/scripts/{moveToFinished-13.js → moveToFinished-14.js} +89 -88
  138. package/dist/esm/scripts/{moveToFinished-13.js.map → moveToFinished-14.js.map} +1 -1
  139. package/dist/esm/scripts/moveToWaitingChildren-4.js +6 -3
  140. package/dist/esm/scripts/moveToWaitingChildren-4.js.map +1 -1
  141. package/dist/esm/scripts/pause-7.js +64 -0
  142. package/dist/esm/scripts/pause-7.js.map +1 -0
  143. package/dist/esm/scripts/promote-8.js +76 -0
  144. package/dist/esm/scripts/promote-8.js.map +1 -0
  145. package/dist/esm/scripts/{retryJob-9.js → retryJob-10.js} +26 -32
  146. package/dist/esm/scripts/retryJob-10.js.map +1 -0
  147. package/dist/esm/tsconfig.tsbuildinfo +1 -1
  148. package/package.json +1 -1
  149. package/dist/cjs/commands/changePriority-5.lua +0 -52
  150. package/dist/cjs/commands/includes/addPriorityMarkerIfNeeded.lua +0 -12
  151. package/dist/cjs/commands/moveToDelayed-8.lua +0 -72
  152. package/dist/cjs/commands/pause-5.lua +0 -36
  153. package/dist/cjs/commands/promote-7.lua +0 -57
  154. package/dist/cjs/scripts/addDelayedJob-7.js.map +0 -1
  155. package/dist/cjs/scripts/addPrioritizedJob-8.js.map +0 -1
  156. package/dist/cjs/scripts/addStandardJob-6.js.map +0 -1
  157. package/dist/cjs/scripts/changePriority-5.js +0 -87
  158. package/dist/cjs/scripts/changePriority-5.js.map +0 -1
  159. package/dist/cjs/scripts/moveToDelayed-8.js +0 -168
  160. package/dist/cjs/scripts/moveToDelayed-8.js.map +0 -1
  161. package/dist/cjs/scripts/pause-5.js +0 -48
  162. package/dist/cjs/scripts/pause-5.js.map +0 -1
  163. package/dist/cjs/scripts/promote-7.js +0 -87
  164. package/dist/cjs/scripts/promote-7.js.map +0 -1
  165. package/dist/cjs/scripts/retryJob-9.js.map +0 -1
  166. package/dist/esm/commands/changePriority-5.lua +0 -52
  167. package/dist/esm/commands/includes/addPriorityMarkerIfNeeded.lua +0 -12
  168. package/dist/esm/commands/moveToDelayed-8.lua +0 -72
  169. package/dist/esm/commands/pause-5.lua +0 -36
  170. package/dist/esm/commands/promote-7.lua +0 -57
  171. package/dist/esm/scripts/addDelayedJob-7.js.map +0 -1
  172. package/dist/esm/scripts/addPrioritizedJob-8.js.map +0 -1
  173. package/dist/esm/scripts/addStandardJob-6.js.map +0 -1
  174. package/dist/esm/scripts/changePriority-5.js +0 -84
  175. package/dist/esm/scripts/changePriority-5.js.map +0 -1
  176. package/dist/esm/scripts/moveToDelayed-8.js +0 -165
  177. package/dist/esm/scripts/moveToDelayed-8.js.map +0 -1
  178. package/dist/esm/scripts/pause-5.js +0 -45
  179. package/dist/esm/scripts/pause-5.js.map +0 -1
  180. package/dist/esm/scripts/promote-7.js +0 -84
  181. package/dist/esm/scripts/promote-7.js.map +0 -1
  182. package/dist/esm/scripts/retryJob-9.js.map +0 -1
  183. /package/dist/esm/scripts/{addDelayedJob-7.d.ts → addDelayedJob-6.d.ts} +0 -0
  184. /package/dist/esm/scripts/{addPrioritizedJob-8.d.ts → addPrioritizedJob-7.d.ts} +0 -0
  185. /package/dist/esm/scripts/{addStandardJob-6.d.ts → addStandardJob-7.d.ts} +0 -0
  186. /package/dist/esm/scripts/{changePriority-5.d.ts → changePriority-6.d.ts} +0 -0
  187. /package/dist/esm/scripts/{moveToActive-10.d.ts → moveToActive-11.d.ts} +0 -0
  188. /package/dist/esm/scripts/{moveToDelayed-8.d.ts → moveToDelayed-7.d.ts} +0 -0
  189. /package/dist/esm/scripts/{moveToFinished-13.d.ts → moveToFinished-14.d.ts} +0 -0
  190. /package/dist/esm/scripts/{pause-5.d.ts → pause-7.d.ts} +0 -0
  191. /package/dist/esm/scripts/{promote-7.d.ts → promote-8.d.ts} +0 -0
  192. /package/dist/esm/scripts/{retryJob-9.d.ts → retryJob-10.d.ts} +0 -0
@@ -18,20 +18,19 @@ const content = `--[[
18
18
  KEYS[11] completed/failed key
19
19
  KEYS[12] jobId key
20
20
  KEYS[13] metrics key
21
+ KEYS[14] marker key
21
22
  ARGV[1] jobId
22
23
  ARGV[2] timestamp
23
24
  ARGV[3] msg property returnvalue / failedReason
24
25
  ARGV[4] return value / failed reason
25
26
  ARGV[5] target (completed/failed)
26
- ARGV[6] event data (? maybe just send jobid).
27
- ARGV[7] fetch next?
28
- ARGV[8] keys prefix
29
- ARGV[9] opts
27
+ ARGV[6] fetch next?
28
+ ARGV[7] keys prefix
29
+ ARGV[8] opts
30
30
  opts - token - lock token
31
31
  opts - keepJobs
32
32
  opts - lockDuration - lock duration in milliseconds
33
33
  opts - attempts max attempts
34
- opts - attemptsMade
35
34
  opts - maxMetricsSize
36
35
  opts - fpof - fail parent on fail
37
36
  opts - rdof - remove dependency on fail
@@ -187,7 +186,7 @@ local function prepareJobForProcessing(keys, keyPrefix, targetKey, jobId, proces
187
186
  end
188
187
  rcall("XADD", keys[4], "*", "event", "active", "jobId", jobId, "prev", "waiting")
189
188
  rcall("HSET", jobKey, "processedOn", processedOn)
190
- rcall("HINCRBY", jobKey, "attemptsMade", 1)
189
+ rcall("HINCRBY", jobKey, "ats", 1)
191
190
  return {rcall("HGETALL", jobKey), jobId, 0, 0} -- get job data
192
191
  end
193
192
  --[[
@@ -200,49 +199,32 @@ end
200
199
  -- Includes
201
200
  --[[
202
201
  Add delay marker if needed.
203
- ]]
202
+ ]]
204
203
  -- Includes
205
- local function addDelayMarkerIfNeeded(targetKey, delayedKey)
206
- local waitLen = rcall("LLEN", targetKey)
207
- if waitLen <= 1 then
204
+ local function addDelayMarkerIfNeeded(markerKey, delayedKey)
208
205
  local nextTimestamp = getNextDelayedTimestamp(delayedKey)
209
206
  if nextTimestamp ~= nil then
210
- -- Check if there is already a marker with older timestamp
211
- -- if there is, we need to replace it.
212
- if waitLen == 1 then
213
- local marker = rcall("LINDEX", targetKey, 0)
214
- local oldTimestamp = tonumber(marker:sub(3))
215
- if oldTimestamp and oldTimestamp > nextTimestamp then
216
- rcall("LSET", targetKey, 0, "0:" .. nextTimestamp)
217
- end
218
- else
219
- -- if there is no marker, then we need to add one
220
- rcall("LPUSH", targetKey, "0:" .. nextTimestamp)
221
- end
207
+ -- Replace the score of the marker with the newest known
208
+ -- next timestamp.
209
+ rcall("ZADD", markerKey, nextTimestamp, "0")
222
210
  end
223
- end
224
211
  end
225
212
  --[[
226
- Function to add job considering priority.
213
+ Function to check for the meta.paused key to decide if we are paused or not
214
+ (since an empty list and !EXISTS are not really the same).
227
215
  ]]
228
- -- Includes
216
+ local function isQueuePaused(queueMetaKey)
217
+ return rcall("HEXISTS", queueMetaKey, "paused") == 1
218
+ end
229
219
  --[[
230
- Function priority marker to wait if needed
231
- in order to wake up our workers and to respect priority
232
- order as much as possible
220
+ Function to add job considering priority.
233
221
  ]]
234
- local function addPriorityMarkerIfNeeded(waitKey)
235
- local waitLen = rcall("LLEN", waitKey)
236
- if waitLen == 0 then
237
- rcall("LPUSH", waitKey, "0:0")
238
- end
239
- end
240
- local function addJobWithPriority(waitKey, prioritizedKey, priority, paused, jobId, priorityCounterKey)
222
+ local function addJobWithPriority(markerKey, prioritizedKey, priority, jobId, priorityCounterKey, isPaused)
241
223
  local prioCounter = rcall("INCR", priorityCounterKey)
242
224
  local score = priority * 0x100000000 + bit.band(prioCounter, 0xffffffffffff)
243
225
  rcall("ZADD", prioritizedKey, score, jobId)
244
- if not paused then
245
- addPriorityMarkerIfNeeded(waitKey)
226
+ if not isPaused then
227
+ rcall("ZADD", markerKey, 0, "0")
246
228
  end
247
229
  end
248
230
  --[[
@@ -256,35 +238,44 @@ local function getTargetQueueList(queueMetaKey, waitKey, pausedKey)
256
238
  return pausedKey, true
257
239
  end
258
240
  end
259
- local function moveParentToWaitIfNeeded(parentQueueKey, parentDependenciesKey, parentKey, parentId, timestamp)
260
- local isParentActive = rcall("ZSCORE", parentQueueKey .. ":waiting-children", parentId)
261
- if rcall("SCARD", parentDependenciesKey) == 0 and isParentActive then
262
- rcall("ZREM", parentQueueKey .. ":waiting-children", parentId)
263
- local parentWaitKey = parentQueueKey .. ":wait"
264
- local parentTarget, paused = getTargetQueueList(parentQueueKey .. ":meta", parentWaitKey,
265
- parentQueueKey .. ":paused")
266
- local jobAttributes = rcall("HMGET", parentKey, "priority", "delay")
267
- local priority = tonumber(jobAttributes[1]) or 0
268
- local delay = tonumber(jobAttributes[2]) or 0
269
- if delay > 0 then
270
- local delayedTimestamp = tonumber(timestamp) + delay
271
- local score = delayedTimestamp * 0x1000
272
- local parentDelayedKey = parentQueueKey .. ":delayed"
273
- rcall("ZADD", parentDelayedKey, score, parentId)
274
- rcall("XADD", parentQueueKey .. ":events", "*", "event", "delayed", "jobId", parentId,
275
- "delay", delayedTimestamp)
276
- addDelayMarkerIfNeeded(parentTarget, parentDelayedKey)
277
- else
278
- if priority == 0 then
279
- rcall("RPUSH", parentTarget, parentId)
280
- else
281
- addJobWithPriority(parentWaitKey, parentQueueKey .. ":prioritized", priority, paused,
282
- parentId, parentQueueKey .. ":pc")
283
- end
284
- rcall("XADD", parentQueueKey .. ":events", "*", "event", "waiting", "jobId", parentId,
285
- "prev", "waiting-children")
241
+ local function moveParentToWaitIfNeeded(parentQueueKey, parentDependenciesKey,
242
+ parentKey, parentId, timestamp)
243
+ local isParentActive = rcall("ZSCORE",
244
+ parentQueueKey .. ":waiting-children", parentId)
245
+ if rcall("SCARD", parentDependenciesKey) == 0 and isParentActive then
246
+ rcall("ZREM", parentQueueKey .. ":waiting-children", parentId)
247
+ local parentWaitKey = parentQueueKey .. ":wait"
248
+ local parentPausedKey = parentQueueKey .. ":paused"
249
+ local parentMetaKey = parentQueueKey .. ":meta"
250
+ local parentMarkerKey = parentQueueKey .. ":marker"
251
+ local jobAttributes = rcall("HMGET", parentKey, "priority", "delay")
252
+ local priority = tonumber(jobAttributes[1]) or 0
253
+ local delay = tonumber(jobAttributes[2]) or 0
254
+ if delay > 0 then
255
+ local delayedTimestamp = tonumber(timestamp) + delay
256
+ local score = delayedTimestamp * 0x1000
257
+ local parentDelayedKey = parentQueueKey .. ":delayed"
258
+ rcall("ZADD", parentDelayedKey, score, parentId)
259
+ rcall("XADD", parentQueueKey .. ":events", "*", "event", "delayed",
260
+ "jobId", parentId, "delay", delayedTimestamp)
261
+ addDelayMarkerIfNeeded(parentMarkerKey, parentDelayedKey)
262
+ else
263
+ if priority == 0 then
264
+ local parentTarget, _paused =
265
+ getTargetQueueList(parentMetaKey, parentWaitKey,
266
+ parentPausedKey)
267
+ rcall("RPUSH", parentTarget, parentId)
268
+ rcall("ZADD", parentMarkerKey, 0, "0")
269
+ else
270
+ local isPaused = isQueuePaused(parentMetaKey)
271
+ addJobWithPriority(parentMarkerKey,
272
+ parentQueueKey .. ":prioritized", priority,
273
+ parentId, parentQueueKey .. ":pc", isPaused)
274
+ end
275
+ rcall("XADD", parentQueueKey .. ":events", "*", "event", "waiting",
276
+ "jobId", parentId, "prev", "waiting-children")
277
+ end
286
278
  end
287
- end
288
279
  end
289
280
  local function moveParentFromWaitingChildrenToFailed( parentQueueKey, parentKey, parentId, jobIdKey, timestamp)
290
281
  if rcall("ZREM", parentQueueKey .. ":waiting-children", parentId) == 1 then
@@ -323,8 +314,8 @@ end
323
314
  ]]
324
315
  -- Includes
325
316
  -- Try to get as much as 1000 jobs at once
326
- local function promoteDelayedJobs(delayedKey, waitKey, targetKey, prioritizedKey,
327
- eventStreamKey, prefix, timestamp, paused, priorityCounterKey)
317
+ local function promoteDelayedJobs(delayedKey, markerKey, targetKey, prioritizedKey,
318
+ eventStreamKey, prefix, timestamp, priorityCounterKey, isPaused)
328
319
  local jobs = rcall("ZRANGEBYSCORE", delayedKey, 0, (timestamp + 1) * 0x1000, "LIMIT", 0, 1000)
329
320
  if (#jobs > 0) then
330
321
  rcall("ZREM", delayedKey, unpack(jobs))
@@ -335,9 +326,12 @@ local function promoteDelayedJobs(delayedKey, waitKey, targetKey, prioritizedKey
335
326
  if priority == 0 then
336
327
  -- LIFO or FIFO
337
328
  rcall("LPUSH", targetKey, jobId)
329
+ if not isPaused then
330
+ rcall("ZADD", markerKey, 0, "0")
331
+ end
338
332
  else
339
- addJobWithPriority(waitKey, prioritizedKey, priority, paused,
340
- jobId, priorityCounterKey)
333
+ addJobWithPriority(markerKey, prioritizedKey, priority,
334
+ jobId, priorityCounterKey, isPaused)
341
335
  end
342
336
  -- Emit waiting event
343
337
  rcall("XADD", eventStreamKey, "*", "event", "waiting", "jobId",
@@ -492,10 +486,9 @@ local function getRateLimitTTL(maxJobs, rateLimiterKey)
492
486
  end
493
487
  local jobIdKey = KEYS[12]
494
488
  if rcall("EXISTS", jobIdKey) == 1 then -- // Make sure job exists
495
- local opts = cmsgpack.unpack(ARGV[9])
489
+ local opts = cmsgpack.unpack(ARGV[8])
496
490
  local token = opts['token']
497
491
  local attempts = opts['attempts']
498
- local attemptsMade = opts['attemptsMade']
499
492
  local maxMetricsSize = opts['maxMetricsSize']
500
493
  local maxCount = opts['keepJobs']['count']
501
494
  local maxAge = opts['keepJobs']['age']
@@ -532,8 +525,9 @@ if rcall("EXISTS", jobIdKey) == 1 then -- // Make sure job exists
532
525
  -- Remove from active list (if not active we shall return error)
533
526
  local numRemovedElements = rcall("LREM", KEYS[2], -1, jobId)
534
527
  if (numRemovedElements < 1) then return -3 end
528
+ local metaKey = KEYS[9]
535
529
  -- Trim events before emiting them to avoid trimming events emitted in this script
536
- trimEvents(KEYS[9], KEYS[4])
530
+ trimEvents(metaKey, KEYS[4])
537
531
  -- If job has a parent we need to
538
532
  -- 1) remove this job id from parents dependencies
539
533
  -- 2) move the job Id to parent "processed" set
@@ -554,16 +548,18 @@ if rcall("EXISTS", jobIdKey) == 1 then -- // Make sure job exists
554
548
  else
555
549
  if opts['fpof'] then
556
550
  moveParentFromWaitingChildrenToFailed(parentQueueKey, parentKey,
557
- parentId, jobIdKey, timestamp)
551
+ parentId, jobIdKey,
552
+ timestamp)
558
553
  elseif opts['rdof'] then
559
554
  local dependenciesSet = parentKey .. ":dependencies"
560
555
  if rcall("SREM", dependenciesSet, jobIdKey) == 1 then
561
556
  moveParentToWaitIfNeeded(parentQueueKey, dependenciesSet,
562
- parentKey, parentId, timestamp)
557
+ parentKey, parentId, timestamp)
563
558
  end
564
559
  end
565
560
  end
566
561
  end
562
+ local attemptsMade = rcall("HINCRBY", jobIdKey, "atm", 1)
567
563
  -- Remove job?
568
564
  if maxCount ~= 0 then
569
565
  local targetSet = KEYS[11]
@@ -572,7 +568,7 @@ if rcall("EXISTS", jobIdKey) == 1 then -- // Make sure job exists
572
568
  rcall("HMSET", jobIdKey, ARGV[3], ARGV[4], "finishedOn", timestamp)
573
569
  -- "returnvalue" / "failedReason" and "finishedOn"
574
570
  -- Remove old jobs?
575
- local prefix = ARGV[8]
571
+ local prefix = ARGV[7]
576
572
  if maxAge ~= nil then
577
573
  removeJobsByMaxAge(timestamp, maxAge, targetSet, prefix)
578
574
  end
@@ -599,11 +595,11 @@ if rcall("EXISTS", jobIdKey) == 1 then -- // Make sure job exists
599
595
  end
600
596
  -- Try to get next job to avoid an extra roundtrip if the queue is not closing,
601
597
  -- and not rate limited.
602
- if (ARGV[7] == "1") then
603
- local target, paused = getTargetQueueList(KEYS[9], KEYS[1], KEYS[8])
598
+ if (ARGV[6] == "1") then
599
+ local target, paused = getTargetQueueList(metaKey, KEYS[1], KEYS[8])
604
600
  -- Check if there are delayed jobs that can be promoted
605
- promoteDelayedJobs(KEYS[7], KEYS[1], target, KEYS[3],
606
- KEYS[4], ARGV[8], timestamp, paused, KEYS[10])
601
+ promoteDelayedJobs(KEYS[7], KEYS[14], target, KEYS[3], KEYS[4], ARGV[7],
602
+ timestamp, KEYS[10], paused)
607
603
  local maxJobs = tonumber(opts['limiter'] and opts['limiter']['max'])
608
604
  -- Check if we are rate limited first.
609
605
  local expireTime = getRateLimitTTL(maxJobs, KEYS[6])
@@ -612,24 +608,29 @@ if rcall("EXISTS", jobIdKey) == 1 then -- // Make sure job exists
612
608
  if paused then return {0, 0, 0, 0} end
613
609
  jobId = rcall("RPOPLPUSH", KEYS[1], KEYS[2])
614
610
  if jobId then
611
+ -- Markers in waitlist DEPRECATED in v5: Remove in v6.
615
612
  if string.sub(jobId, 1, 2) == "0:" then
616
613
  rcall("LREM", KEYS[2], 1, jobId)
617
614
  -- If jobId is special ID 0:delay (delay greater than 0), then there is no job to process
618
615
  -- but if ID is 0:0, then there is at least 1 prioritized job to process
619
616
  if jobId == "0:0" then
620
- jobId = moveJobFromPriorityToActive(KEYS[3], KEYS[2], KEYS[10])
621
- return prepareJobForProcessing(KEYS, ARGV[8], target, jobId, timestamp,
622
- maxJobs, expireTime, opts)
617
+ jobId = moveJobFromPriorityToActive(KEYS[3], KEYS[2],
618
+ KEYS[10])
619
+ return prepareJobForProcessing(KEYS, ARGV[7], target, jobId,
620
+ timestamp, maxJobs,
621
+ expireTime, opts)
623
622
  end
624
623
  else
625
- return prepareJobForProcessing(KEYS, ARGV[8], target, jobId, timestamp, maxJobs,
626
- expireTime, opts)
624
+ return prepareJobForProcessing(KEYS, ARGV[7], target, jobId,
625
+ timestamp, maxJobs, expireTime,
626
+ opts)
627
627
  end
628
628
  else
629
629
  jobId = moveJobFromPriorityToActive(KEYS[3], KEYS[2], KEYS[10])
630
630
  if jobId then
631
- return prepareJobForProcessing(KEYS, ARGV[8], target, jobId, timestamp, maxJobs,
632
- expireTime, opts)
631
+ return prepareJobForProcessing(KEYS, ARGV[7], target, jobId,
632
+ timestamp, maxJobs, expireTime,
633
+ opts)
633
634
  end
634
635
  end
635
636
  -- Return the timestamp for the next delayed job if any.
@@ -658,6 +659,6 @@ end
658
659
  export const moveToFinished = {
659
660
  name: 'moveToFinished',
660
661
  content,
661
- keys: 13,
662
+ keys: 14,
662
663
  };
663
- //# sourceMappingURL=moveToFinished-13.js.map
664
+ //# sourceMappingURL=moveToFinished-14.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"moveToFinished-13.js","sourceRoot":"","sources":["../../../src/scripts/moveToFinished-13.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgpBf,CAAC;AACF,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,IAAI,EAAE,gBAAgB;IACtB,OAAO;IACP,IAAI,EAAE,EAAE;CACT,CAAC"}
1
+ {"version":3,"file":"moveToFinished-14.js","sourceRoot":"","sources":["../../../src/scripts/moveToFinished-14.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAipBf,CAAC;AACF,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,IAAI,EAAE,gBAAgB;IACtB,OAAO;IACP,IAAI,EAAE,EAAE;CACT,CAAC"}
@@ -17,7 +17,8 @@ const content = `--[[
17
17
  -3 - Job not in active set
18
18
  ]]
19
19
  local rcall = redis.call
20
- local function moveToWaitingChildren (activeKey, waitingChildrenKey, jobId, timestamp, lockKey, token)
20
+ local function moveToWaitingChildren (activeKey, waitingChildrenKey, jobId, timestamp,
21
+ lockKey, jobKey, token)
21
22
  if token ~= "0" then
22
23
  if rcall("GET", lockKey) == token then
23
24
  rcall("DEL", lockKey)
@@ -36,12 +37,14 @@ end
36
37
  if rcall("EXISTS", KEYS[4]) == 1 then
37
38
  if ARGV[2] ~= "" then
38
39
  if rcall("SISMEMBER", KEYS[4] .. ":dependencies", ARGV[2]) ~= 0 then
39
- return moveToWaitingChildren(KEYS[2], KEYS[3], ARGV[4], ARGV[3], KEYS[1], ARGV[1])
40
+ return moveToWaitingChildren(KEYS[2], KEYS[3], ARGV[4], ARGV[3], KEYS[1], KEYS[4],
41
+ ARGV[1])
40
42
  end
41
43
  return 1
42
44
  else
43
45
  if rcall("SCARD", KEYS[4] .. ":dependencies") ~= 0 then
44
- return moveToWaitingChildren(KEYS[2], KEYS[3], ARGV[4], ARGV[3], KEYS[1], ARGV[1])
46
+ return moveToWaitingChildren(KEYS[2], KEYS[3], ARGV[4], ARGV[3], KEYS[1], KEYS[4],
47
+ ARGV[1])
45
48
  end
46
49
  return 1
47
50
  end
@@ -1 +1 @@
1
- {"version":3,"file":"moveToWaitingChildren-4.js","sourceRoot":"","sources":["../../../src/scripts/moveToWaitingChildren-4.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiDf,CAAC;AACF,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,IAAI,EAAE,uBAAuB;IAC7B,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
1
+ {"version":3,"file":"moveToWaitingChildren-4.js","sourceRoot":"","sources":["../../../src/scripts/moveToWaitingChildren-4.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAoDf,CAAC;AACF,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,IAAI,EAAE,uBAAuB;IAC7B,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
@@ -0,0 +1,64 @@
1
+ const content = `--[[
2
+ Pauses or resumes a queue globably.
3
+ Input:
4
+ KEYS[1] 'wait' or 'paused''
5
+ KEYS[2] 'paused' or 'wait'
6
+ KEYS[3] 'meta'
7
+ KEYS[4] 'prioritized'
8
+ KEYS[5] events stream key
9
+ KEYS[6] 'delayed'
10
+ KEYS|7] 'marker'
11
+ ARGV[1] 'paused' or 'resumed'
12
+ Event:
13
+ publish paused or resumed event.
14
+ ]]
15
+ local rcall = redis.call
16
+ -- Includes
17
+ --[[
18
+ Add delay marker if needed.
19
+ ]]
20
+ -- Includes
21
+ --[[
22
+ Function to return the next delayed job timestamp.
23
+ ]]
24
+ local function getNextDelayedTimestamp(delayedKey)
25
+ local result = rcall("ZRANGE", delayedKey, 0, 0, "WITHSCORES")
26
+ if #result then
27
+ local nextTimestamp = tonumber(result[2])
28
+ if (nextTimestamp ~= nil) then
29
+ nextTimestamp = nextTimestamp / 0x1000
30
+ end
31
+ return nextTimestamp
32
+ end
33
+ end
34
+ local function addDelayMarkerIfNeeded(markerKey, delayedKey)
35
+ local nextTimestamp = getNextDelayedTimestamp(delayedKey)
36
+ if nextTimestamp ~= nil then
37
+ -- Replace the score of the marker with the newest known
38
+ -- next timestamp.
39
+ rcall("ZADD", markerKey, nextTimestamp, "0")
40
+ end
41
+ end
42
+ local markerKey = KEYS[7]
43
+ local hasJobs = rcall("EXISTS", KEYS[1]) == 1
44
+ if hasJobs then rcall("RENAME", KEYS[1], KEYS[2]) end
45
+ if ARGV[1] == "paused" then
46
+ rcall("HSET", KEYS[3], "paused", 1)
47
+ rcall("DEL", markerKey)
48
+ else
49
+ rcall("HDEL", KEYS[3], "paused")
50
+ if hasJobs or rcall("ZCARD", KEYS[4]) > 0 then
51
+ -- Add marker if there are waiting or priority jobs
52
+ rcall("ZADD", markerKey, 0, "0")
53
+ else
54
+ addDelayMarkerIfNeeded(markerKey, KEYS[6])
55
+ end
56
+ end
57
+ rcall("XADD", KEYS[5], "*", "event", ARGV[1]);
58
+ `;
59
+ export const pause = {
60
+ name: 'pause',
61
+ content,
62
+ keys: 7,
63
+ };
64
+ //# sourceMappingURL=pause-7.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pause-7.js","sourceRoot":"","sources":["../../../src/scripts/pause-7.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyDf,CAAC;AACF,MAAM,CAAC,MAAM,KAAK,GAAG;IACnB,IAAI,EAAE,OAAO;IACb,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
@@ -0,0 +1,76 @@
1
+ const content = `--[[
2
+ Promotes a job that is currently "delayed" to the "waiting" state
3
+ Input:
4
+ KEYS[1] 'delayed'
5
+ KEYS[2] 'wait'
6
+ KEYS[3] 'paused'
7
+ KEYS[4] 'meta'
8
+ KEYS[5] 'prioritized'
9
+ KEYS[6] 'pc' priority counter
10
+ KEYS[7] 'event stream'
11
+ KEYS[8] 'marker'
12
+ ARGV[1] queue.toKey('')
13
+ ARGV[2] jobId
14
+ Output:
15
+ 0 - OK
16
+ -3 - Job not in delayed zset.
17
+ Events:
18
+ 'waiting'
19
+ ]]
20
+ local rcall = redis.call
21
+ local jobId = ARGV[2]
22
+ -- Includes
23
+ --[[
24
+ Function to add job considering priority.
25
+ ]]
26
+ local function addJobWithPriority(markerKey, prioritizedKey, priority, jobId, priorityCounterKey, isPaused)
27
+ local prioCounter = rcall("INCR", priorityCounterKey)
28
+ local score = priority * 0x100000000 + bit.band(prioCounter, 0xffffffffffff)
29
+ rcall("ZADD", prioritizedKey, score, jobId)
30
+ if not isPaused then
31
+ rcall("ZADD", markerKey, 0, "0")
32
+ end
33
+ end
34
+ --[[
35
+ Function to check for the meta.paused key to decide if we are paused or not
36
+ (since an empty list and !EXISTS are not really the same).
37
+ ]]
38
+ local function getTargetQueueList(queueMetaKey, waitKey, pausedKey)
39
+ if rcall("HEXISTS", queueMetaKey, "paused") ~= 1 then
40
+ return waitKey, false
41
+ else
42
+ return pausedKey, true
43
+ end
44
+ end
45
+ if rcall("ZREM", KEYS[1], jobId) == 1 then
46
+ local jobKey = ARGV[1] .. jobId
47
+ local priority = tonumber(rcall("HGET", jobKey, "priority")) or 0
48
+ local metaKey = KEYS[4]
49
+ -- Remove delayed "marker" from the wait list if there is any.
50
+ -- Since we are adding a job we do not need the marker anymore.
51
+ -- Markers in waitlist DEPRECATED in v5: Remove in v6.
52
+ local target, paused = getTargetQueueList(metaKey, KEYS[2], KEYS[3])
53
+ local marker = rcall("LINDEX", target, 0)
54
+ if marker and string.sub(marker, 1, 2) == "0:" then rcall("LPOP", target) end
55
+ if priority == 0 then
56
+ -- LIFO or FIFO
57
+ rcall("LPUSH", target, jobId)
58
+ if not paused then rcall("ZADD", KEYS[8], 0, "0") end
59
+ else
60
+ addJobWithPriority(KEYS[8], KEYS[5], priority, jobId, KEYS[6], paused)
61
+ end
62
+ -- Emit waiting event (wait..ing@token)
63
+ rcall("XADD", KEYS[7], "*", "event", "waiting", "jobId", jobId, "prev",
64
+ "delayed");
65
+ rcall("HSET", jobKey, "delay", 0)
66
+ return 0
67
+ else
68
+ return -3
69
+ end
70
+ `;
71
+ export const promote = {
72
+ name: 'promote',
73
+ content,
74
+ keys: 8,
75
+ };
76
+ //# sourceMappingURL=promote-8.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"promote-8.js","sourceRoot":"","sources":["../../../src/scripts/promote-8.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAqEf,CAAC;AACF,MAAM,CAAC,MAAM,OAAO,GAAG;IACrB,IAAI,EAAE,SAAS;IACf,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
@@ -1,15 +1,16 @@
1
1
  const content = `--[[
2
2
  Retries a failed job by moving it back to the wait queue.
3
3
  Input:
4
- KEYS[1] 'active',
5
- KEYS[2] 'wait'
6
- KEYS[3] 'paused'
7
- KEYS[4] job key
8
- KEYS[5] 'meta'
9
- KEYS[6] events stream
10
- KEYS[7] delayed key
11
- KEYS[8] prioritized key
12
- KEYS[9] 'pc' priority counter
4
+ KEYS[1] 'active',
5
+ KEYS[2] 'wait'
6
+ KEYS[3] 'paused'
7
+ KEYS[4] job key
8
+ KEYS[5] 'meta'
9
+ KEYS[6] events stream
10
+ KEYS[7] delayed key
11
+ KEYS[8] prioritized key
12
+ KEYS[9] 'pc' priority counter
13
+ KEYS[10] 'marker'
13
14
  ARGV[1] key prefix
14
15
  ARGV[2] timestamp
15
16
  ARGV[3] pushCmd
@@ -27,24 +28,12 @@ local rcall = redis.call
27
28
  --[[
28
29
  Function to add job considering priority.
29
30
  ]]
30
- -- Includes
31
- --[[
32
- Function priority marker to wait if needed
33
- in order to wake up our workers and to respect priority
34
- order as much as possible
35
- ]]
36
- local function addPriorityMarkerIfNeeded(waitKey)
37
- local waitLen = rcall("LLEN", waitKey)
38
- if waitLen == 0 then
39
- rcall("LPUSH", waitKey, "0:0")
40
- end
41
- end
42
- local function addJobWithPriority(waitKey, prioritizedKey, priority, paused, jobId, priorityCounterKey)
31
+ local function addJobWithPriority(markerKey, prioritizedKey, priority, jobId, priorityCounterKey, isPaused)
43
32
  local prioCounter = rcall("INCR", priorityCounterKey)
44
33
  local score = priority * 0x100000000 + bit.band(prioCounter, 0xffffffffffff)
45
34
  rcall("ZADD", prioritizedKey, score, jobId)
46
- if not paused then
47
- addPriorityMarkerIfNeeded(waitKey)
35
+ if not isPaused then
36
+ rcall("ZADD", markerKey, 0, "0")
48
37
  end
49
38
  end
50
39
  --[[
@@ -66,8 +55,8 @@ end
66
55
  ]]
67
56
  -- Includes
68
57
  -- Try to get as much as 1000 jobs at once
69
- local function promoteDelayedJobs(delayedKey, waitKey, targetKey, prioritizedKey,
70
- eventStreamKey, prefix, timestamp, paused, priorityCounterKey)
58
+ local function promoteDelayedJobs(delayedKey, markerKey, targetKey, prioritizedKey,
59
+ eventStreamKey, prefix, timestamp, priorityCounterKey, isPaused)
71
60
  local jobs = rcall("ZRANGEBYSCORE", delayedKey, 0, (timestamp + 1) * 0x1000, "LIMIT", 0, 1000)
72
61
  if (#jobs > 0) then
73
62
  rcall("ZREM", delayedKey, unpack(jobs))
@@ -78,9 +67,12 @@ local function promoteDelayedJobs(delayedKey, waitKey, targetKey, prioritizedKey
78
67
  if priority == 0 then
79
68
  -- LIFO or FIFO
80
69
  rcall("LPUSH", targetKey, jobId)
70
+ if not isPaused then
71
+ rcall("ZADD", markerKey, 0, "0")
72
+ end
81
73
  else
82
- addJobWithPriority(waitKey, prioritizedKey, priority, paused,
83
- jobId, priorityCounterKey)
74
+ addJobWithPriority(markerKey, prioritizedKey, priority,
75
+ jobId, priorityCounterKey, isPaused)
84
76
  end
85
77
  -- Emit waiting event
86
78
  rcall("XADD", eventStreamKey, "*", "event", "waiting", "jobId",
@@ -90,9 +82,10 @@ local function promoteDelayedJobs(delayedKey, waitKey, targetKey, prioritizedKey
90
82
  end
91
83
  end
92
84
  local target, paused = getTargetQueueList(KEYS[5], KEYS[2], KEYS[3])
85
+ local markerKey = KEYS[10]
93
86
  -- Check if there are delayed jobs that we can move to wait.
94
87
  -- test example: when there are delayed jobs between retries
95
- promoteDelayedJobs(KEYS[7], KEYS[2], target, KEYS[8], KEYS[6], ARGV[1], ARGV[2], paused, KEYS[9])
88
+ promoteDelayedJobs(KEYS[7], markerKey, target, KEYS[8], KEYS[6], ARGV[1], ARGV[2], KEYS[9], paused)
96
89
  if rcall("EXISTS", KEYS[4]) == 1 then
97
90
  if ARGV[5] ~= "0" then
98
91
  local lockKey = KEYS[4] .. ':lock'
@@ -108,8 +101,9 @@ if rcall("EXISTS", KEYS[4]) == 1 then
108
101
  if priority == 0 then
109
102
  rcall(ARGV[3], target, ARGV[4])
110
103
  else
111
- addJobWithPriority(KEYS[2], KEYS[8], priority, paused, ARGV[4], KEYS[9])
104
+ addJobWithPriority(markerKey, KEYS[8], priority, ARGV[4], KEYS[9], paused)
112
105
  end
106
+ rcall("HINCRBY", KEYS[4], "atm", 1)
113
107
  local maxEvents = rcall("HGET", KEYS[5], "opts.maxLenEvents") or 10000
114
108
  -- Emit waiting event
115
109
  rcall("XADD", KEYS[6], "MAXLEN", "~", maxEvents, "*", "event", "waiting",
@@ -122,6 +116,6 @@ end
122
116
  export const retryJob = {
123
117
  name: 'retryJob',
124
118
  content,
125
- keys: 9,
119
+ keys: 10,
126
120
  };
127
- //# sourceMappingURL=retryJob-9.js.map
121
+ //# sourceMappingURL=retryJob-10.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"retryJob-10.js","sourceRoot":"","sources":["../../../src/scripts/retryJob-10.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkHf,CAAC;AACF,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,IAAI,EAAE,UAAU;IAChB,OAAO;IACP,IAAI,EAAE,EAAE;CACT,CAAC"}