bullmq 5.8.7 → 5.10.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 (205) hide show
  1. package/dist/cjs/classes/queue.js +29 -0
  2. package/dist/cjs/classes/queue.js.map +1 -1
  3. package/dist/cjs/classes/repeat.js +44 -30
  4. package/dist/cjs/classes/repeat.js.map +1 -1
  5. package/dist/cjs/classes/scripts.js +44 -5
  6. package/dist/cjs/classes/scripts.js.map +1 -1
  7. package/dist/cjs/classes/worker.js +1 -1
  8. package/dist/cjs/classes/worker.js.map +1 -1
  9. package/dist/cjs/commands/{addPrioritizedJob-7.lua → addPrioritizedJob-8.lua} +9 -7
  10. package/dist/cjs/commands/addRepeatableJob-2.lua +69 -0
  11. package/dist/cjs/commands/{addStandardJob-7.lua → addStandardJob-8.lua} +6 -5
  12. package/dist/cjs/commands/{changePriority-6.lua → changePriority-7.lua} +12 -10
  13. package/dist/cjs/commands/getCountsPerPriority-4.lua +6 -3
  14. package/dist/cjs/commands/includes/addBaseMarkerIfNeeded.lua +2 -2
  15. package/dist/cjs/commands/includes/addJobInTargetList.lua +2 -2
  16. package/dist/cjs/commands/includes/addJobWithPriority.lua +3 -2
  17. package/dist/cjs/commands/includes/getTargetQueueList.lua +14 -4
  18. package/dist/cjs/commands/includes/isQueueMaxed.lua +15 -0
  19. package/dist/cjs/commands/includes/isQueuePaused.lua +1 -1
  20. package/dist/cjs/commands/includes/isQueuePausedOrMaxed.lua +18 -0
  21. package/dist/cjs/commands/includes/moveParentToWaitIfNeeded.lua +8 -6
  22. package/dist/cjs/commands/includes/removeParentDependencyKey.lua +3 -3
  23. package/dist/cjs/commands/isMaxed-2.lua +17 -0
  24. package/dist/cjs/commands/moveJobFromActiveToWait-10.lua +2 -2
  25. package/dist/{esm/commands/moveJobsToWait-7.lua → cjs/commands/moveJobsToWait-8.lua} +4 -3
  26. package/dist/cjs/commands/moveStalledJobsToWait-9.lua +3 -3
  27. package/dist/cjs/commands/moveToActive-11.lua +4 -4
  28. package/dist/cjs/commands/moveToFinished-14.lua +4 -4
  29. package/dist/cjs/commands/moveToWaitingChildren-5.lua +4 -3
  30. package/dist/cjs/commands/obliterate-2.lua +23 -8
  31. package/dist/{esm/commands/promote-8.lua → cjs/commands/promote-9.lua} +9 -7
  32. package/dist/{esm/commands/removeJob-1.lua → cjs/commands/removeJob-2.lua} +2 -1
  33. package/dist/cjs/commands/removeRepeatable-2.lua +27 -6
  34. package/dist/{esm/commands/reprocessJob-7.lua → cjs/commands/reprocessJob-8.lua} +4 -3
  35. package/dist/cjs/commands/retryJob-11.lua +8 -4
  36. package/dist/cjs/interfaces/index.js +1 -0
  37. package/dist/cjs/interfaces/index.js.map +1 -1
  38. package/dist/cjs/interfaces/repeatable-options.js +3 -0
  39. package/dist/cjs/interfaces/repeatable-options.js.map +1 -0
  40. package/dist/cjs/scripts/addDelayedJob-6.js +39 -18
  41. package/dist/cjs/scripts/addDelayedJob-6.js.map +1 -1
  42. package/dist/cjs/scripts/addParentJob-4.js +39 -18
  43. package/dist/cjs/scripts/addParentJob-4.js.map +1 -1
  44. package/dist/cjs/scripts/{addPrioritizedJob-7.js → addPrioritizedJob-8.js} +49 -26
  45. package/dist/cjs/scripts/addPrioritizedJob-8.js.map +1 -0
  46. package/dist/cjs/scripts/addRepeatableJob-2.js +66 -0
  47. package/dist/cjs/scripts/addRepeatableJob-2.js.map +1 -0
  48. package/dist/cjs/scripts/{addStandardJob-7.js → addStandardJob-8.js} +47 -25
  49. package/dist/cjs/scripts/addStandardJob-8.js.map +1 -0
  50. package/dist/cjs/scripts/{changePriority-6.js → changePriority-7.js} +33 -21
  51. package/dist/cjs/scripts/changePriority-7.js.map +1 -0
  52. package/dist/cjs/scripts/cleanJobsInSet-2.js +20 -11
  53. package/dist/cjs/scripts/cleanJobsInSet-2.js.map +1 -1
  54. package/dist/cjs/scripts/drain-4.js +20 -11
  55. package/dist/cjs/scripts/drain-4.js.map +1 -1
  56. package/dist/cjs/scripts/getCountsPerPriority-4.js +7 -8
  57. package/dist/cjs/scripts/getCountsPerPriority-4.js.map +1 -1
  58. package/dist/cjs/scripts/index.js +9 -7
  59. package/dist/cjs/scripts/index.js.map +1 -1
  60. package/dist/cjs/scripts/isMaxed-2.js +34 -0
  61. package/dist/cjs/scripts/isMaxed-2.js.map +1 -0
  62. package/dist/cjs/scripts/moveJobFromActiveToWait-10.js +19 -10
  63. package/dist/cjs/scripts/moveJobFromActiveToWait-10.js.map +1 -1
  64. package/dist/cjs/scripts/{moveJobsToWait-7.js → moveJobsToWait-8.js} +21 -11
  65. package/dist/cjs/scripts/moveJobsToWait-8.js.map +1 -0
  66. package/dist/cjs/scripts/moveStalledJobsToWait-9.js +45 -24
  67. package/dist/cjs/scripts/moveStalledJobsToWait-9.js.map +1 -1
  68. package/dist/cjs/scripts/moveToActive-11.js +24 -14
  69. package/dist/cjs/scripts/moveToActive-11.js.map +1 -1
  70. package/dist/cjs/scripts/moveToFinished-14.js +46 -25
  71. package/dist/cjs/scripts/moveToFinished-14.js.map +1 -1
  72. package/dist/cjs/scripts/moveToWaitingChildren-5.js +4 -3
  73. package/dist/cjs/scripts/moveToWaitingChildren-5.js.map +1 -1
  74. package/dist/cjs/scripts/obliterate-2.js +41 -18
  75. package/dist/cjs/scripts/obliterate-2.js.map +1 -1
  76. package/dist/cjs/scripts/{promote-8.js → promote-9.js} +31 -19
  77. package/dist/cjs/scripts/promote-9.js.map +1 -0
  78. package/dist/cjs/scripts/removeChildDependency-1.js +20 -11
  79. package/dist/cjs/scripts/removeChildDependency-1.js.map +1 -1
  80. package/dist/cjs/scripts/{removeJob-1.js → removeJob-2.js} +24 -14
  81. package/dist/cjs/scripts/{removeJob-1.js.map → removeJob-2.js.map} +1 -1
  82. package/dist/cjs/scripts/removeRepeatable-2.js +29 -6
  83. package/dist/cjs/scripts/removeRepeatable-2.js.map +1 -1
  84. package/dist/cjs/scripts/{reprocessJob-7.js → reprocessJob-8.js} +23 -13
  85. package/dist/cjs/scripts/reprocessJob-8.js.map +1 -0
  86. package/dist/cjs/scripts/retryJob-11.js +42 -14
  87. package/dist/cjs/scripts/retryJob-11.js.map +1 -1
  88. package/dist/cjs/tsconfig-cjs.tsbuildinfo +1 -1
  89. package/dist/esm/classes/queue.d.ts +17 -0
  90. package/dist/esm/classes/queue.js +29 -0
  91. package/dist/esm/classes/queue.js.map +1 -1
  92. package/dist/esm/classes/repeat.d.ts +2 -0
  93. package/dist/esm/classes/repeat.js +44 -30
  94. package/dist/esm/classes/repeat.js.map +1 -1
  95. package/dist/esm/classes/scripts.d.ts +6 -2
  96. package/dist/esm/classes/scripts.js +44 -5
  97. package/dist/esm/classes/scripts.js.map +1 -1
  98. package/dist/esm/classes/worker.js +1 -1
  99. package/dist/esm/classes/worker.js.map +1 -1
  100. package/dist/esm/commands/{addPrioritizedJob-7.lua → addPrioritizedJob-8.lua} +9 -7
  101. package/dist/esm/commands/addRepeatableJob-2.lua +69 -0
  102. package/dist/esm/commands/{addStandardJob-7.lua → addStandardJob-8.lua} +6 -5
  103. package/dist/esm/commands/{changePriority-6.lua → changePriority-7.lua} +12 -10
  104. package/dist/esm/commands/getCountsPerPriority-4.lua +6 -3
  105. package/dist/esm/commands/includes/addBaseMarkerIfNeeded.lua +2 -2
  106. package/dist/esm/commands/includes/addJobInTargetList.lua +2 -2
  107. package/dist/esm/commands/includes/addJobWithPriority.lua +3 -2
  108. package/dist/esm/commands/includes/getTargetQueueList.lua +14 -4
  109. package/dist/esm/commands/includes/isQueueMaxed.lua +15 -0
  110. package/dist/esm/commands/includes/isQueuePaused.lua +1 -1
  111. package/dist/esm/commands/includes/isQueuePausedOrMaxed.lua +18 -0
  112. package/dist/esm/commands/includes/moveParentToWaitIfNeeded.lua +8 -6
  113. package/dist/esm/commands/includes/removeParentDependencyKey.lua +3 -3
  114. package/dist/esm/commands/isMaxed-2.lua +17 -0
  115. package/dist/esm/commands/moveJobFromActiveToWait-10.lua +2 -2
  116. package/dist/{cjs/commands/moveJobsToWait-7.lua → esm/commands/moveJobsToWait-8.lua} +4 -3
  117. package/dist/esm/commands/moveStalledJobsToWait-9.lua +3 -3
  118. package/dist/esm/commands/moveToActive-11.lua +4 -4
  119. package/dist/esm/commands/moveToFinished-14.lua +4 -4
  120. package/dist/esm/commands/moveToWaitingChildren-5.lua +4 -3
  121. package/dist/esm/commands/obliterate-2.lua +23 -8
  122. package/dist/{cjs/commands/promote-8.lua → esm/commands/promote-9.lua} +9 -7
  123. package/dist/{cjs/commands/removeJob-1.lua → esm/commands/removeJob-2.lua} +2 -1
  124. package/dist/esm/commands/removeRepeatable-2.lua +27 -6
  125. package/dist/{cjs/commands/reprocessJob-7.lua → esm/commands/reprocessJob-8.lua} +4 -3
  126. package/dist/esm/commands/retryJob-11.lua +8 -4
  127. package/dist/esm/interfaces/index.d.ts +1 -0
  128. package/dist/esm/interfaces/index.js +1 -0
  129. package/dist/esm/interfaces/index.js.map +1 -1
  130. package/dist/esm/interfaces/repeatable-job.d.ts +3 -2
  131. package/dist/esm/interfaces/repeatable-options.d.ts +7 -0
  132. package/dist/esm/interfaces/repeatable-options.js +2 -0
  133. package/dist/esm/interfaces/repeatable-options.js.map +1 -0
  134. package/dist/esm/scripts/addDelayedJob-6.js +39 -18
  135. package/dist/esm/scripts/addDelayedJob-6.js.map +1 -1
  136. package/dist/esm/scripts/addParentJob-4.js +39 -18
  137. package/dist/esm/scripts/addParentJob-4.js.map +1 -1
  138. package/dist/esm/scripts/{addPrioritizedJob-7.js → addPrioritizedJob-8.js} +49 -26
  139. package/dist/esm/scripts/addPrioritizedJob-8.js.map +1 -0
  140. package/dist/esm/scripts/addRepeatableJob-2.d.ts +5 -0
  141. package/dist/esm/scripts/addRepeatableJob-2.js +63 -0
  142. package/dist/esm/scripts/addRepeatableJob-2.js.map +1 -0
  143. package/dist/esm/scripts/{addStandardJob-7.js → addStandardJob-8.js} +47 -25
  144. package/dist/esm/scripts/addStandardJob-8.js.map +1 -0
  145. package/dist/esm/scripts/{changePriority-6.js → changePriority-7.js} +33 -21
  146. package/dist/esm/scripts/changePriority-7.js.map +1 -0
  147. package/dist/esm/scripts/cleanJobsInSet-2.js +20 -11
  148. package/dist/esm/scripts/cleanJobsInSet-2.js.map +1 -1
  149. package/dist/esm/scripts/drain-4.js +20 -11
  150. package/dist/esm/scripts/drain-4.js.map +1 -1
  151. package/dist/esm/scripts/getCountsPerPriority-4.js +7 -8
  152. package/dist/esm/scripts/getCountsPerPriority-4.js.map +1 -1
  153. package/dist/esm/scripts/index.d.ts +9 -7
  154. package/dist/esm/scripts/index.js +9 -7
  155. package/dist/esm/scripts/index.js.map +1 -1
  156. package/dist/esm/scripts/isMaxed-2.d.ts +5 -0
  157. package/dist/esm/scripts/isMaxed-2.js +31 -0
  158. package/dist/esm/scripts/isMaxed-2.js.map +1 -0
  159. package/dist/esm/scripts/moveJobFromActiveToWait-10.js +19 -10
  160. package/dist/esm/scripts/moveJobFromActiveToWait-10.js.map +1 -1
  161. package/dist/esm/scripts/{moveJobsToWait-7.js → moveJobsToWait-8.js} +21 -11
  162. package/dist/esm/scripts/moveJobsToWait-8.js.map +1 -0
  163. package/dist/esm/scripts/moveStalledJobsToWait-9.js +45 -24
  164. package/dist/esm/scripts/moveStalledJobsToWait-9.js.map +1 -1
  165. package/dist/esm/scripts/moveToActive-11.js +24 -14
  166. package/dist/esm/scripts/moveToActive-11.js.map +1 -1
  167. package/dist/esm/scripts/moveToFinished-14.js +46 -25
  168. package/dist/esm/scripts/moveToFinished-14.js.map +1 -1
  169. package/dist/esm/scripts/moveToWaitingChildren-5.js +4 -3
  170. package/dist/esm/scripts/moveToWaitingChildren-5.js.map +1 -1
  171. package/dist/esm/scripts/obliterate-2.js +41 -18
  172. package/dist/esm/scripts/obliterate-2.js.map +1 -1
  173. package/dist/esm/scripts/{promote-8.js → promote-9.js} +31 -19
  174. package/dist/esm/scripts/promote-9.js.map +1 -0
  175. package/dist/esm/scripts/removeChildDependency-1.js +20 -11
  176. package/dist/esm/scripts/removeChildDependency-1.js.map +1 -1
  177. package/dist/esm/scripts/{removeJob-1.js → removeJob-2.js} +24 -14
  178. package/dist/esm/scripts/{removeJob-1.js.map → removeJob-2.js.map} +1 -1
  179. package/dist/esm/scripts/removeRepeatable-2.js +29 -6
  180. package/dist/esm/scripts/removeRepeatable-2.js.map +1 -1
  181. package/dist/esm/scripts/{reprocessJob-7.js → reprocessJob-8.js} +23 -13
  182. package/dist/esm/scripts/reprocessJob-8.js.map +1 -0
  183. package/dist/esm/scripts/retryJob-11.js +42 -14
  184. package/dist/esm/scripts/retryJob-11.js.map +1 -1
  185. package/dist/esm/tsconfig.tsbuildinfo +1 -1
  186. package/package.json +2 -1
  187. package/dist/cjs/scripts/addPrioritizedJob-7.js.map +0 -1
  188. package/dist/cjs/scripts/addStandardJob-7.js.map +0 -1
  189. package/dist/cjs/scripts/changePriority-6.js.map +0 -1
  190. package/dist/cjs/scripts/moveJobsToWait-7.js.map +0 -1
  191. package/dist/cjs/scripts/promote-8.js.map +0 -1
  192. package/dist/cjs/scripts/reprocessJob-7.js.map +0 -1
  193. package/dist/esm/scripts/addPrioritizedJob-7.js.map +0 -1
  194. package/dist/esm/scripts/addStandardJob-7.js.map +0 -1
  195. package/dist/esm/scripts/changePriority-6.js.map +0 -1
  196. package/dist/esm/scripts/moveJobsToWait-7.js.map +0 -1
  197. package/dist/esm/scripts/promote-8.js.map +0 -1
  198. package/dist/esm/scripts/reprocessJob-7.js.map +0 -1
  199. /package/dist/esm/scripts/{addPrioritizedJob-7.d.ts → addPrioritizedJob-8.d.ts} +0 -0
  200. /package/dist/esm/scripts/{addStandardJob-7.d.ts → addStandardJob-8.d.ts} +0 -0
  201. /package/dist/esm/scripts/{changePriority-6.d.ts → changePriority-7.d.ts} +0 -0
  202. /package/dist/esm/scripts/{moveJobsToWait-7.d.ts → moveJobsToWait-8.d.ts} +0 -0
  203. /package/dist/esm/scripts/{promote-8.d.ts → promote-9.d.ts} +0 -0
  204. /package/dist/esm/scripts/{removeJob-1.d.ts → removeJob-2.d.ts} +0 -0
  205. /package/dist/esm/scripts/{reprocessJob-7.d.ts → reprocessJob-8.d.ts} +0 -0
@@ -29,14 +29,14 @@ local rcall = redis.call
29
29
  --[[
30
30
  Add marker if needed when a job is available.
31
31
  ]]
32
- local function addBaseMarkerIfNeeded(markerKey, isPaused)
33
- if not isPaused then
32
+ local function addBaseMarkerIfNeeded(markerKey, isPausedOrMaxed)
33
+ if not isPausedOrMaxed then
34
34
  rcall("ZADD", markerKey, 0, "0")
35
35
  end
36
36
  end
37
- local function addJobInTargetList(targetKey, markerKey, pushCmd, isPaused, jobId)
37
+ local function addJobInTargetList(targetKey, markerKey, pushCmd, isPausedOrMaxed, jobId)
38
38
  rcall(pushCmd, targetKey, jobId)
39
- addBaseMarkerIfNeeded(markerKey, isPaused)
39
+ addBaseMarkerIfNeeded(markerKey, isPausedOrMaxed)
40
40
  end
41
41
  --[[
42
42
  Function to loop in batches.
@@ -58,12 +58,21 @@ end
58
58
  Function to check for the meta.paused key to decide if we are paused or not
59
59
  (since an empty list and !EXISTS are not really the same).
60
60
  ]]
61
- local function getTargetQueueList(queueMetaKey, waitKey, pausedKey)
62
- if rcall("HEXISTS", queueMetaKey, "paused") ~= 1 then
63
- return waitKey, false
64
- else
61
+ local function getTargetQueueList(queueMetaKey, activeKey, waitKey, pausedKey)
62
+ local queueAttributes = rcall("HMGET", queueMetaKey, "paused", "concurrency")
63
+ if queueAttributes[1] then
65
64
  return pausedKey, true
65
+ else
66
+ if queueAttributes[2] then
67
+ local activeCount = rcall("LLEN", activeKey)
68
+ if activeCount >= tonumber(queueAttributes[2]) then
69
+ return waitKey, true
70
+ else
71
+ return waitKey, false
72
+ end
73
+ end
66
74
  end
75
+ return waitKey, false
67
76
  end
68
77
  --[[
69
78
  Function to recursively move from waitingChildren to failed.
@@ -101,18 +110,28 @@ end
101
110
  Function to add job considering priority.
102
111
  ]]
103
112
  -- Includes
104
- local function addJobWithPriority(markerKey, prioritizedKey, priority, jobId, priorityCounterKey, isPaused)
113
+ local function addJobWithPriority(markerKey, prioritizedKey, priority, jobId, priorityCounterKey,
114
+ isPausedOrMaxed)
105
115
  local prioCounter = rcall("INCR", priorityCounterKey)
106
116
  local score = priority * 0x100000000 + prioCounter % 0x100000000
107
117
  rcall("ZADD", prioritizedKey, score, jobId)
108
- addBaseMarkerIfNeeded(markerKey, isPaused)
118
+ addBaseMarkerIfNeeded(markerKey, isPausedOrMaxed)
109
119
  end
110
120
  --[[
111
- Function to check for the meta.paused key to decide if we are paused or not
121
+ Function to check if queue is paused or maxed
112
122
  (since an empty list and !EXISTS are not really the same).
113
123
  ]]
114
- local function isQueuePaused(queueMetaKey)
115
- return rcall("HEXISTS", queueMetaKey, "paused") == 1
124
+ local function isQueuePausedOrMaxed(queueMetaKey, activeKey)
125
+ local queueAttributes = rcall("HMGET", queueMetaKey, "paused", "concurrency")
126
+ if queueAttributes[1] then
127
+ return true
128
+ else
129
+ if queueAttributes[2] then
130
+ local activeCount = rcall("LLEN", activeKey)
131
+ return activeCount >= tonumber(queueAttributes[2])
132
+ end
133
+ end
134
+ return false
116
135
  end
117
136
  local function moveParentToWaitIfNeeded(parentQueueKey, parentDependenciesKey,
118
137
  parentKey, parentId, timestamp)
@@ -122,6 +141,7 @@ local function moveParentToWaitIfNeeded(parentQueueKey, parentDependenciesKey,
122
141
  rcall("ZREM", parentQueueKey .. ":waiting-children", parentId)
123
142
  local parentWaitKey = parentQueueKey .. ":wait"
124
143
  local parentPausedKey = parentQueueKey .. ":paused"
144
+ local parentActiveKey = parentQueueKey .. ":active"
125
145
  local parentMetaKey = parentQueueKey .. ":meta"
126
146
  local parentMarkerKey = parentQueueKey .. ":marker"
127
147
  local jobAttributes = rcall("HMGET", parentKey, "priority", "delay")
@@ -137,15 +157,16 @@ local function moveParentToWaitIfNeeded(parentQueueKey, parentDependenciesKey,
137
157
  addDelayMarkerIfNeeded(parentMarkerKey, parentDelayedKey)
138
158
  else
139
159
  if priority == 0 then
140
- local parentTarget, isParentPaused =
141
- getTargetQueueList(parentMetaKey, parentWaitKey,
160
+ local parentTarget, isParentPausedOrMaxed =
161
+ getTargetQueueList(parentMetaKey, parentActiveKey, parentWaitKey,
142
162
  parentPausedKey)
143
- addJobInTargetList(parentTarget, parentMarkerKey, "RPUSH", isParentPaused, parentId)
163
+ addJobInTargetList(parentTarget, parentMarkerKey, "RPUSH", isParentPausedOrMaxed,
164
+ parentId)
144
165
  else
145
- local isPaused = isQueuePaused(parentMetaKey)
166
+ local isPausedOrMaxed = isQueuePausedOrMaxed(parentMetaKey, parentActiveKey)
146
167
  addJobWithPriority(parentMarkerKey,
147
168
  parentQueueKey .. ":prioritized", priority,
148
- parentId, parentQueueKey .. ":pc", isPaused)
169
+ parentId, parentQueueKey .. ":pc", isPausedOrMaxed)
149
170
  end
150
171
  rcall("XADD", parentQueueKey .. ":events", "*", "event", "waiting",
151
172
  "jobId", parentId, "prev", "waiting-children")
@@ -209,9 +230,9 @@ local getJobKeyPrefix = function (jobKey, jobId)
209
230
  return string.sub(jobKey, 0, #jobKey - #jobId)
210
231
  end
211
232
  local function moveParentToWait(parentPrefix, parentId, emitEvent)
212
- local parentTarget, isPaused = getTargetQueueList(parentPrefix .. "meta", parentPrefix .. "wait",
213
- parentPrefix .. "paused")
214
- addJobInTargetList(parentTarget, parentPrefix .. "marker", "RPUSH", isPaused, parentId)
233
+ local parentTarget, isPausedOrMaxed = getTargetQueueList(parentPrefix .. "meta", parentPrefix .. "active",
234
+ parentPrefix .. "wait", parentPrefix .. "paused")
235
+ addJobInTargetList(parentTarget, parentPrefix .. "marker", "RPUSH", isPausedOrMaxed, parentId)
215
236
  if emitEvent then
216
237
  local parentEventStream = parentPrefix .. "events"
217
238
  rcall("XADD", parentEventStream, "*", "event", "waiting", "jobId", parentId, "prev", "waiting-children")
@@ -421,10 +442,10 @@ if (#stalling > 0) then
421
442
  end
422
443
  table.insert(failed, jobId)
423
444
  else
424
- local target, isPaused=
425
- getTargetQueueList(metaKey, waitKey, pausedKey)
445
+ local target, isPausedOrMaxed=
446
+ getTargetQueueList(metaKey, activeKey, waitKey, pausedKey)
426
447
  -- Move the job back to the wait queue, to immediately be picked up by a waiting worker.
427
- addJobInTargetList(target, markerKey, "RPUSH", isPaused, jobId)
448
+ addJobInTargetList(target, markerKey, "RPUSH", isPausedOrMaxed, jobId)
428
449
  rcall("XADD", eventStreamKey, "*", "event",
429
450
  "waiting", "jobId", jobId, 'prev', 'active')
430
451
  -- Emit the stalled event
@@ -1 +1 @@
1
- {"version":3,"file":"moveStalledJobsToWait-9.js","sourceRoot":"","sources":["../../../src/scripts/moveStalledJobsToWait-9.ts"],"names":[],"mappings":";;;AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;yBA2bS,CAAC;AACb,QAAA,qBAAqB,GAAG;IACnC,IAAI,EAAE,uBAAuB;IAC7B,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
1
+ {"version":3,"file":"moveStalledJobsToWait-9.js","sourceRoot":"","sources":["../../../src/scripts/moveStalledJobsToWait-9.ts"],"names":[],"mappings":";;;AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;yBAgdS,CAAC;AACb,QAAA,qBAAqB,GAAG;IACnC,IAAI,EAAE,uBAAuB;IAC7B,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
@@ -69,12 +69,21 @@ end
69
69
  Function to check for the meta.paused key to decide if we are paused or not
70
70
  (since an empty list and !EXISTS are not really the same).
71
71
  ]]
72
- local function getTargetQueueList(queueMetaKey, waitKey, pausedKey)
73
- if rcall("HEXISTS", queueMetaKey, "paused") ~= 1 then
74
- return waitKey, false
75
- else
72
+ local function getTargetQueueList(queueMetaKey, activeKey, waitKey, pausedKey)
73
+ local queueAttributes = rcall("HMGET", queueMetaKey, "paused", "concurrency")
74
+ if queueAttributes[1] then
76
75
  return pausedKey, true
76
+ else
77
+ if queueAttributes[2] then
78
+ local activeCount = rcall("LLEN", activeKey)
79
+ if activeCount >= tonumber(queueAttributes[2]) then
80
+ return waitKey, true
81
+ else
82
+ return waitKey, false
83
+ end
84
+ end
77
85
  end
86
+ return waitKey, false
78
87
  end
79
88
  --[[
80
89
  Function to move job from prioritized state to active.
@@ -137,24 +146,25 @@ end
137
146
  --[[
138
147
  Add marker if needed when a job is available.
139
148
  ]]
140
- local function addBaseMarkerIfNeeded(markerKey, isPaused)
141
- if not isPaused then
149
+ local function addBaseMarkerIfNeeded(markerKey, isPausedOrMaxed)
150
+ if not isPausedOrMaxed then
142
151
  rcall("ZADD", markerKey, 0, "0")
143
152
  end
144
153
  end
145
- local function addJobInTargetList(targetKey, markerKey, pushCmd, isPaused, jobId)
154
+ local function addJobInTargetList(targetKey, markerKey, pushCmd, isPausedOrMaxed, jobId)
146
155
  rcall(pushCmd, targetKey, jobId)
147
- addBaseMarkerIfNeeded(markerKey, isPaused)
156
+ addBaseMarkerIfNeeded(markerKey, isPausedOrMaxed)
148
157
  end
149
158
  --[[
150
159
  Function to add job considering priority.
151
160
  ]]
152
161
  -- Includes
153
- local function addJobWithPriority(markerKey, prioritizedKey, priority, jobId, priorityCounterKey, isPaused)
162
+ local function addJobWithPriority(markerKey, prioritizedKey, priority, jobId, priorityCounterKey,
163
+ isPausedOrMaxed)
154
164
  local prioCounter = rcall("INCR", priorityCounterKey)
155
165
  local score = priority * 0x100000000 + prioCounter % 0x100000000
156
166
  rcall("ZADD", prioritizedKey, score, jobId)
157
- addBaseMarkerIfNeeded(markerKey, isPaused)
167
+ addBaseMarkerIfNeeded(markerKey, isPausedOrMaxed)
158
168
  end
159
169
  -- Try to get as much as 1000 jobs at once
160
170
  local function promoteDelayedJobs(delayedKey, markerKey, targetKey, prioritizedKey,
@@ -180,17 +190,17 @@ local function promoteDelayedJobs(delayedKey, markerKey, targetKey, prioritizedK
180
190
  end
181
191
  end
182
192
  end
183
- local target, paused = getTargetQueueList(KEYS[9], waitKey, KEYS[8])
193
+ local target, isPausedOrMaxed = getTargetQueueList(KEYS[9], activeKey, waitKey, KEYS[8])
184
194
  -- Check if there are delayed jobs that we can move to wait.
185
195
  local markerKey = KEYS[11]
186
196
  promoteDelayedJobs(delayedKey, markerKey, target, KEYS[3], eventStreamKey, ARGV[1],
187
- ARGV[2], KEYS[10], paused)
197
+ ARGV[2], KEYS[10], isPausedOrMaxed)
188
198
  local maxJobs = tonumber(opts['limiter'] and opts['limiter']['max'])
189
199
  local expireTime = getRateLimitTTL(maxJobs, rateLimiterKey)
190
200
  -- Check if we are rate limited first.
191
201
  if expireTime > 0 then return {0, 0, expireTime, 0} end
192
- -- paused queue
193
- if paused then return {0, 0, 0, 0} end
202
+ -- paused or maxed queue
203
+ if isPausedOrMaxed then return {0, 0, 0, 0} end
194
204
  -- no job ID, try non-blocking move from wait to active
195
205
  local jobId = rcall("RPOPLPUSH", waitKey, activeKey)
196
206
  -- Markers in waitlist DEPRECATED in v5: Will be completely removed in v6.
@@ -1 +1 @@
1
- {"version":3,"file":"moveToActive-11.js","sourceRoot":"","sources":["../../../src/scripts/moveToActive-11.ts"],"names":[],"mappings":";;;AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAmNf,CAAC;AACW,QAAA,YAAY,GAAG;IAC1B,IAAI,EAAE,cAAc;IACpB,OAAO;IACP,IAAI,EAAE,EAAE;CACT,CAAC"}
1
+ {"version":3,"file":"moveToActive-11.js","sourceRoot":"","sources":["../../../src/scripts/moveToActive-11.ts"],"names":[],"mappings":";;;AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6Nf,CAAC;AACW,QAAA,YAAY,GAAG;IAC1B,IAAI,EAAE,cAAc;IACpB,OAAO;IACP,IAAI,EAAE,EAAE;CACT,CAAC"}
@@ -135,12 +135,21 @@ end
135
135
  Function to check for the meta.paused key to decide if we are paused or not
136
136
  (since an empty list and !EXISTS are not really the same).
137
137
  ]]
138
- local function getTargetQueueList(queueMetaKey, waitKey, pausedKey)
139
- if rcall("HEXISTS", queueMetaKey, "paused") ~= 1 then
140
- return waitKey, false
141
- else
138
+ local function getTargetQueueList(queueMetaKey, activeKey, waitKey, pausedKey)
139
+ local queueAttributes = rcall("HMGET", queueMetaKey, "paused", "concurrency")
140
+ if queueAttributes[1] then
142
141
  return pausedKey, true
142
+ else
143
+ if queueAttributes[2] then
144
+ local activeCount = rcall("LLEN", activeKey)
145
+ if activeCount >= tonumber(queueAttributes[2]) then
146
+ return waitKey, true
147
+ else
148
+ return waitKey, false
149
+ end
150
+ end
143
151
  end
152
+ return waitKey, false
144
153
  end
145
154
  --[[
146
155
  Function to move job from prioritized state to active.
@@ -181,31 +190,41 @@ end
181
190
  --[[
182
191
  Add marker if needed when a job is available.
183
192
  ]]
184
- local function addBaseMarkerIfNeeded(markerKey, isPaused)
185
- if not isPaused then
193
+ local function addBaseMarkerIfNeeded(markerKey, isPausedOrMaxed)
194
+ if not isPausedOrMaxed then
186
195
  rcall("ZADD", markerKey, 0, "0")
187
196
  end
188
197
  end
189
- local function addJobInTargetList(targetKey, markerKey, pushCmd, isPaused, jobId)
198
+ local function addJobInTargetList(targetKey, markerKey, pushCmd, isPausedOrMaxed, jobId)
190
199
  rcall(pushCmd, targetKey, jobId)
191
- addBaseMarkerIfNeeded(markerKey, isPaused)
200
+ addBaseMarkerIfNeeded(markerKey, isPausedOrMaxed)
192
201
  end
193
202
  --[[
194
203
  Function to add job considering priority.
195
204
  ]]
196
205
  -- Includes
197
- local function addJobWithPriority(markerKey, prioritizedKey, priority, jobId, priorityCounterKey, isPaused)
206
+ local function addJobWithPriority(markerKey, prioritizedKey, priority, jobId, priorityCounterKey,
207
+ isPausedOrMaxed)
198
208
  local prioCounter = rcall("INCR", priorityCounterKey)
199
209
  local score = priority * 0x100000000 + prioCounter % 0x100000000
200
210
  rcall("ZADD", prioritizedKey, score, jobId)
201
- addBaseMarkerIfNeeded(markerKey, isPaused)
211
+ addBaseMarkerIfNeeded(markerKey, isPausedOrMaxed)
202
212
  end
203
213
  --[[
204
- Function to check for the meta.paused key to decide if we are paused or not
214
+ Function to check if queue is paused or maxed
205
215
  (since an empty list and !EXISTS are not really the same).
206
216
  ]]
207
- local function isQueuePaused(queueMetaKey)
208
- return rcall("HEXISTS", queueMetaKey, "paused") == 1
217
+ local function isQueuePausedOrMaxed(queueMetaKey, activeKey)
218
+ local queueAttributes = rcall("HMGET", queueMetaKey, "paused", "concurrency")
219
+ if queueAttributes[1] then
220
+ return true
221
+ else
222
+ if queueAttributes[2] then
223
+ local activeCount = rcall("LLEN", activeKey)
224
+ return activeCount >= tonumber(queueAttributes[2])
225
+ end
226
+ end
227
+ return false
209
228
  end
210
229
  local function moveParentToWaitIfNeeded(parentQueueKey, parentDependenciesKey,
211
230
  parentKey, parentId, timestamp)
@@ -215,6 +234,7 @@ local function moveParentToWaitIfNeeded(parentQueueKey, parentDependenciesKey,
215
234
  rcall("ZREM", parentQueueKey .. ":waiting-children", parentId)
216
235
  local parentWaitKey = parentQueueKey .. ":wait"
217
236
  local parentPausedKey = parentQueueKey .. ":paused"
237
+ local parentActiveKey = parentQueueKey .. ":active"
218
238
  local parentMetaKey = parentQueueKey .. ":meta"
219
239
  local parentMarkerKey = parentQueueKey .. ":marker"
220
240
  local jobAttributes = rcall("HMGET", parentKey, "priority", "delay")
@@ -230,15 +250,16 @@ local function moveParentToWaitIfNeeded(parentQueueKey, parentDependenciesKey,
230
250
  addDelayMarkerIfNeeded(parentMarkerKey, parentDelayedKey)
231
251
  else
232
252
  if priority == 0 then
233
- local parentTarget, isParentPaused =
234
- getTargetQueueList(parentMetaKey, parentWaitKey,
253
+ local parentTarget, isParentPausedOrMaxed =
254
+ getTargetQueueList(parentMetaKey, parentActiveKey, parentWaitKey,
235
255
  parentPausedKey)
236
- addJobInTargetList(parentTarget, parentMarkerKey, "RPUSH", isParentPaused, parentId)
256
+ addJobInTargetList(parentTarget, parentMarkerKey, "RPUSH", isParentPausedOrMaxed,
257
+ parentId)
237
258
  else
238
- local isPaused = isQueuePaused(parentMetaKey)
259
+ local isPausedOrMaxed = isQueuePausedOrMaxed(parentMetaKey, parentActiveKey)
239
260
  addJobWithPriority(parentMarkerKey,
240
261
  parentQueueKey .. ":prioritized", priority,
241
- parentId, parentQueueKey .. ":pc", isPaused)
262
+ parentId, parentQueueKey .. ":pc", isPausedOrMaxed)
242
263
  end
243
264
  rcall("XADD", parentQueueKey .. ":events", "*", "event", "waiting",
244
265
  "jobId", parentId, "prev", "waiting-children")
@@ -372,9 +393,9 @@ local getJobKeyPrefix = function (jobKey, jobId)
372
393
  return string.sub(jobKey, 0, #jobKey - #jobId)
373
394
  end
374
395
  local function moveParentToWait(parentPrefix, parentId, emitEvent)
375
- local parentTarget, isPaused = getTargetQueueList(parentPrefix .. "meta", parentPrefix .. "wait",
376
- parentPrefix .. "paused")
377
- addJobInTargetList(parentTarget, parentPrefix .. "marker", "RPUSH", isPaused, parentId)
396
+ local parentTarget, isPausedOrMaxed = getTargetQueueList(parentPrefix .. "meta", parentPrefix .. "active",
397
+ parentPrefix .. "wait", parentPrefix .. "paused")
398
+ addJobInTargetList(parentTarget, parentPrefix .. "marker", "RPUSH", isPausedOrMaxed, parentId)
378
399
  if emitEvent then
379
400
  local parentEventStream = parentPrefix .. "events"
380
401
  rcall("XADD", parentEventStream, "*", "event", "waiting", "jobId", parentId, "prev", "waiting-children")
@@ -621,16 +642,16 @@ if rcall("EXISTS", jobIdKey) == 1 then -- // Make sure job exists
621
642
  -- Try to get next job to avoid an extra roundtrip if the queue is not closing,
622
643
  -- and not rate limited.
623
644
  if (ARGV[6] == "1") then
624
- local target, paused = getTargetQueueList(metaKey, KEYS[1], KEYS[8])
645
+ local target, isPausedOrMaxed = getTargetQueueList(metaKey, KEYS[2], KEYS[1], KEYS[8])
625
646
  -- Check if there are delayed jobs that can be promoted
626
647
  promoteDelayedJobs(KEYS[7], KEYS[14], target, KEYS[3], eventStreamKey, ARGV[7],
627
- timestamp, KEYS[10], paused)
648
+ timestamp, KEYS[10], isPausedOrMaxed)
628
649
  local maxJobs = tonumber(opts['limiter'] and opts['limiter']['max'])
629
650
  -- Check if we are rate limited first.
630
651
  local expireTime = getRateLimitTTL(maxJobs, KEYS[6])
631
652
  if expireTime > 0 then return {0, 0, expireTime, 0} end
632
- -- paused queue
633
- if paused then return {0, 0, 0, 0} end
653
+ -- paused or maxed queue
654
+ if isPausedOrMaxed then return {0, 0, 0, 0} end
634
655
  jobId = rcall("RPOPLPUSH", KEYS[1], KEYS[2])
635
656
  if jobId then
636
657
  -- Markers in waitlist DEPRECATED in v5: Remove in v6.
@@ -1 +1 @@
1
- {"version":3,"file":"moveToFinished-14.js","sourceRoot":"","sources":["../../../src/scripts/moveToFinished-14.ts"],"names":[],"mappings":";;;AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAuqBf,CAAC;AACW,QAAA,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4rBf,CAAC;AACW,QAAA,cAAc,GAAG;IAC5B,IAAI,EAAE,gBAAgB;IACtB,OAAO;IACP,IAAI,EAAE,EAAE;CACT,CAAC"}
@@ -21,7 +21,8 @@ const content = `--[[
21
21
  -3 - Job not in active set
22
22
  ]]
23
23
  local rcall = redis.call
24
- -- Includes
24
+ local stalledKey = KEYS[5]
25
+ --- Includes
25
26
  local function removeLock(jobKey, stalledKey, token, jobId)
26
27
  if token ~= "0" then
27
28
  local lockKey = jobKey .. ':lock'
@@ -54,7 +55,7 @@ end
54
55
  if rcall("EXISTS", KEYS[4]) == 1 then
55
56
  if ARGV[2] ~= "" then
56
57
  if rcall("SISMEMBER", KEYS[4] .. ":dependencies", ARGV[2]) ~= 0 then
57
- local errorCode = removeLock(KEYS[4], KEYS[5], ARGV[1], ARGV[4])
58
+ local errorCode = removeLock(KEYS[4], stalledKey, ARGV[1], ARGV[4])
58
59
  if errorCode < 0 then
59
60
  return errorCode
60
61
  end
@@ -63,7 +64,7 @@ if rcall("EXISTS", KEYS[4]) == 1 then
63
64
  return 1
64
65
  else
65
66
  if rcall("SCARD", KEYS[4] .. ":dependencies") ~= 0 then
66
- local errorCode = removeLock(KEYS[4], KEYS[5], ARGV[1], ARGV[4])
67
+ local errorCode = removeLock(KEYS[4], stalledKey, ARGV[1], ARGV[4])
67
68
  if errorCode < 0 then
68
69
  return errorCode
69
70
  end
@@ -1 +1 @@
1
- {"version":3,"file":"moveToWaitingChildren-5.js","sourceRoot":"","sources":["../../../src/scripts/moveToWaitingChildren-5.ts"],"names":[],"mappings":";;;AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwEf,CAAC;AACW,QAAA,qBAAqB,GAAG;IACnC,IAAI,EAAE,uBAAuB;IAC7B,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
1
+ {"version":3,"file":"moveToWaitingChildren-5.js","sourceRoot":"","sources":["../../../src/scripts/moveToWaitingChildren-5.ts"],"names":[],"mappings":";;;AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyEf,CAAC;AACW,QAAA,qBAAqB,GAAG;IACnC,IAAI,EAAE,uBAAuB;IAC7B,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
@@ -3,18 +3,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.obliterate = void 0;
4
4
  const content = `--[[
5
5
  Completely obliterates a queue and all of its contents
6
+ This command completely destroys a queue including all of its jobs, current or past
7
+ leaving no trace of its existence. Since this script needs to iterate to find all the job
8
+ keys, consider that this call may be slow for very large queues.
9
+ The queue needs to be "paused" or it will return an error
10
+ If the queue has currently active jobs then the script by default will return error,
11
+ however this behaviour can be overrided using the 'force' option.
6
12
  Input:
7
13
  KEYS[1] meta
8
14
  KEYS[2] base
9
15
  ARGV[1] count
10
16
  ARGV[2] force
11
17
  ]]
12
- -- This command completely destroys a queue including all of its jobs, current or past
13
- -- leaving no trace of its existence. Since this script needs to iterate to find all the job
14
- -- keys, consider that this call may be slow for very large queues.
15
- -- The queue needs to be "paused" or it will return an error
16
- -- If the queue has currently active jobs then the script by default will return error,
17
- -- however this behaviour can be overrided using the 'force' option.
18
18
  local maxCount = tonumber(ARGV[1])
19
19
  local baseKey = KEYS[2]
20
20
  local rcall = redis.call
@@ -47,14 +47,14 @@ end
47
47
  --[[
48
48
  Add marker if needed when a job is available.
49
49
  ]]
50
- local function addBaseMarkerIfNeeded(markerKey, isPaused)
51
- if not isPaused then
50
+ local function addBaseMarkerIfNeeded(markerKey, isPausedOrMaxed)
51
+ if not isPausedOrMaxed then
52
52
  rcall("ZADD", markerKey, 0, "0")
53
53
  end
54
54
  end
55
- local function addJobInTargetList(targetKey, markerKey, pushCmd, isPaused, jobId)
55
+ local function addJobInTargetList(targetKey, markerKey, pushCmd, isPausedOrMaxed, jobId)
56
56
  rcall(pushCmd, targetKey, jobId)
57
- addBaseMarkerIfNeeded(markerKey, isPaused)
57
+ addBaseMarkerIfNeeded(markerKey, isPausedOrMaxed)
58
58
  end
59
59
  --[[
60
60
  Functions to destructure job key.
@@ -70,17 +70,26 @@ end
70
70
  Function to check for the meta.paused key to decide if we are paused or not
71
71
  (since an empty list and !EXISTS are not really the same).
72
72
  ]]
73
- local function getTargetQueueList(queueMetaKey, waitKey, pausedKey)
74
- if rcall("HEXISTS", queueMetaKey, "paused") ~= 1 then
75
- return waitKey, false
76
- else
73
+ local function getTargetQueueList(queueMetaKey, activeKey, waitKey, pausedKey)
74
+ local queueAttributes = rcall("HMGET", queueMetaKey, "paused", "concurrency")
75
+ if queueAttributes[1] then
77
76
  return pausedKey, true
77
+ else
78
+ if queueAttributes[2] then
79
+ local activeCount = rcall("LLEN", activeKey)
80
+ if activeCount >= tonumber(queueAttributes[2]) then
81
+ return waitKey, true
82
+ else
83
+ return waitKey, false
84
+ end
85
+ end
78
86
  end
87
+ return waitKey, false
79
88
  end
80
89
  local function moveParentToWait(parentPrefix, parentId, emitEvent)
81
- local parentTarget, isPaused = getTargetQueueList(parentPrefix .. "meta", parentPrefix .. "wait",
82
- parentPrefix .. "paused")
83
- addJobInTargetList(parentTarget, parentPrefix .. "marker", "RPUSH", isPaused, parentId)
90
+ local parentTarget, isPausedOrMaxed = getTargetQueueList(parentPrefix .. "meta", parentPrefix .. "active",
91
+ parentPrefix .. "wait", parentPrefix .. "paused")
92
+ addJobInTargetList(parentTarget, parentPrefix .. "marker", "RPUSH", isPausedOrMaxed, parentId)
84
93
  if emitEvent then
85
94
  local parentEventStream = parentPrefix .. "events"
86
95
  rcall("XADD", parentEventStream, "*", "event", "waiting", "jobId", parentId, "prev", "waiting-children")
@@ -227,6 +236,21 @@ maxCount = removeZSetJobs(delayedKey, true, baseKey, maxCount)
227
236
  if(maxCount <= 0) then
228
237
  return 1
229
238
  end
239
+ local repeatKey = baseKey .. 'repeat'
240
+ local repeatJobsIds = getZSetItems(repeatKey, maxCount)
241
+ for i, key in ipairs(repeatJobsIds) do
242
+ local jobKey = repeatKey .. ":" .. key
243
+ rcall("DEL", jobKey)
244
+ end
245
+ if(#repeatJobsIds > 0) then
246
+ for from, to in batches(#repeatJobsIds, 7000) do
247
+ rcall("ZREM", repeatKey, unpack(repeatJobsIds, from, to))
248
+ end
249
+ end
250
+ maxCount = maxCount - #repeatJobsIds
251
+ if(maxCount <= 0) then
252
+ return 1
253
+ end
230
254
  local completedKey = baseKey .. 'completed'
231
255
  maxCount = removeZSetJobs(completedKey, true, baseKey, maxCount)
232
256
  if(maxCount <= 0) then
@@ -256,7 +280,6 @@ if(maxCount > 0) then
256
280
  baseKey .. 'id',
257
281
  baseKey .. 'pc',
258
282
  baseKey .. 'meta',
259
- baseKey .. 'repeat',
260
283
  baseKey .. 'metrics:completed',
261
284
  baseKey .. 'metrics:completed:data',
262
285
  baseKey .. 'metrics:failed',
@@ -1 +1 @@
1
- {"version":3,"file":"obliterate-2.js","sourceRoot":"","sources":["../../../src/scripts/obliterate-2.ts"],"names":[],"mappings":";;;AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwQf,CAAC;AACW,QAAA,UAAU,GAAG;IACxB,IAAI,EAAE,YAAY;IAClB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
1
+ {"version":3,"file":"obliterate-2.js","sourceRoot":"","sources":["../../../src/scripts/obliterate-2.ts"],"names":[],"mappings":";;;AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+Rf,CAAC;AACW,QAAA,UAAU,GAAG;IACxB,IAAI,EAAE,YAAY;IAClB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
@@ -9,9 +9,10 @@ const content = `--[[
9
9
  KEYS[3] 'paused'
10
10
  KEYS[4] 'meta'
11
11
  KEYS[5] 'prioritized'
12
- KEYS[6] 'pc' priority counter
13
- KEYS[7] 'event stream'
14
- KEYS[8] 'marker'
12
+ KEYS[6] 'active'
13
+ KEYS[7] 'pc' priority counter
14
+ KEYS[8] 'event stream'
15
+ KEYS[9] 'marker'
15
16
  ARGV[1] queue.toKey('')
16
17
  ARGV[2] jobId
17
18
  Output:
@@ -30,54 +31,65 @@ local jobId = ARGV[2]
30
31
  --[[
31
32
  Add marker if needed when a job is available.
32
33
  ]]
33
- local function addBaseMarkerIfNeeded(markerKey, isPaused)
34
- if not isPaused then
34
+ local function addBaseMarkerIfNeeded(markerKey, isPausedOrMaxed)
35
+ if not isPausedOrMaxed then
35
36
  rcall("ZADD", markerKey, 0, "0")
36
37
  end
37
38
  end
38
- local function addJobInTargetList(targetKey, markerKey, pushCmd, isPaused, jobId)
39
+ local function addJobInTargetList(targetKey, markerKey, pushCmd, isPausedOrMaxed, jobId)
39
40
  rcall(pushCmd, targetKey, jobId)
40
- addBaseMarkerIfNeeded(markerKey, isPaused)
41
+ addBaseMarkerIfNeeded(markerKey, isPausedOrMaxed)
41
42
  end
42
43
  --[[
43
44
  Function to add job considering priority.
44
45
  ]]
45
46
  -- Includes
46
- local function addJobWithPriority(markerKey, prioritizedKey, priority, jobId, priorityCounterKey, isPaused)
47
+ local function addJobWithPriority(markerKey, prioritizedKey, priority, jobId, priorityCounterKey,
48
+ isPausedOrMaxed)
47
49
  local prioCounter = rcall("INCR", priorityCounterKey)
48
50
  local score = priority * 0x100000000 + prioCounter % 0x100000000
49
51
  rcall("ZADD", prioritizedKey, score, jobId)
50
- addBaseMarkerIfNeeded(markerKey, isPaused)
52
+ addBaseMarkerIfNeeded(markerKey, isPausedOrMaxed)
51
53
  end
52
54
  --[[
53
55
  Function to check for the meta.paused key to decide if we are paused or not
54
56
  (since an empty list and !EXISTS are not really the same).
55
57
  ]]
56
- local function getTargetQueueList(queueMetaKey, waitKey, pausedKey)
57
- if rcall("HEXISTS", queueMetaKey, "paused") ~= 1 then
58
- return waitKey, false
59
- else
58
+ local function getTargetQueueList(queueMetaKey, activeKey, waitKey, pausedKey)
59
+ local queueAttributes = rcall("HMGET", queueMetaKey, "paused", "concurrency")
60
+ if queueAttributes[1] then
60
61
  return pausedKey, true
62
+ else
63
+ if queueAttributes[2] then
64
+ local activeCount = rcall("LLEN", activeKey)
65
+ if activeCount >= tonumber(queueAttributes[2]) then
66
+ return waitKey, true
67
+ else
68
+ return waitKey, false
69
+ end
70
+ end
61
71
  end
72
+ return waitKey, false
62
73
  end
63
74
  if rcall("ZREM", KEYS[1], jobId) == 1 then
64
75
  local jobKey = ARGV[1] .. jobId
65
76
  local priority = tonumber(rcall("HGET", jobKey, "priority")) or 0
66
77
  local metaKey = KEYS[4]
78
+ local markerKey = KEYS[9]
67
79
  -- Remove delayed "marker" from the wait list if there is any.
68
80
  -- Since we are adding a job we do not need the marker anymore.
69
81
  -- Markers in waitlist DEPRECATED in v5: Remove in v6.
70
- local target, paused = getTargetQueueList(metaKey, KEYS[2], KEYS[3])
82
+ local target, isPausedOrMaxed = getTargetQueueList(metaKey, KEYS[6], KEYS[2], KEYS[3])
71
83
  local marker = rcall("LINDEX", target, 0)
72
84
  if marker and string.sub(marker, 1, 2) == "0:" then rcall("LPOP", target) end
73
85
  if priority == 0 then
74
86
  -- LIFO or FIFO
75
- addJobInTargetList(target, KEYS[8], "LPUSH", paused, jobId)
87
+ addJobInTargetList(target, markerKey, "LPUSH", isPausedOrMaxed, jobId)
76
88
  else
77
- addJobWithPriority(KEYS[8], KEYS[5], priority, jobId, KEYS[6], paused)
89
+ addJobWithPriority(markerKey, KEYS[5], priority, jobId, KEYS[7], isPausedOrMaxed)
78
90
  end
79
91
  -- Emit waiting event (wait..ing@token)
80
- rcall("XADD", KEYS[7], "*", "event", "waiting", "jobId", jobId, "prev",
92
+ rcall("XADD", KEYS[8], "*", "event", "waiting", "jobId", jobId, "prev",
81
93
  "delayed");
82
94
  rcall("HSET", jobKey, "delay", 0)
83
95
  return 0
@@ -88,6 +100,6 @@ end
88
100
  exports.promote = {
89
101
  name: 'promote',
90
102
  content,
91
- keys: 8,
103
+ keys: 9,
92
104
  };
93
- //# sourceMappingURL=promote-8.js.map
105
+ //# sourceMappingURL=promote-9.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"promote-9.js","sourceRoot":"","sources":["../../../src/scripts/promote-9.ts"],"names":[],"mappings":";;;AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+Ff,CAAC;AACW,QAAA,OAAO,GAAG;IACrB,IAAI,EAAE,SAAS;IACf,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}