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