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
@@ -128,42 +128,61 @@ end
128
128
  --[[
129
129
  Add marker if needed when a job is available.
130
130
  ]]
131
- local function addBaseMarkerIfNeeded(markerKey, isPaused)
132
- if not isPaused then
131
+ local function addBaseMarkerIfNeeded(markerKey, isPausedOrMaxed)
132
+ if not isPausedOrMaxed then
133
133
  rcall("ZADD", markerKey, 0, "0")
134
134
  end
135
135
  end
136
- local function addJobInTargetList(targetKey, markerKey, pushCmd, isPaused, jobId)
136
+ local function addJobInTargetList(targetKey, markerKey, pushCmd, isPausedOrMaxed, jobId)
137
137
  rcall(pushCmd, targetKey, jobId)
138
- addBaseMarkerIfNeeded(markerKey, isPaused)
138
+ addBaseMarkerIfNeeded(markerKey, isPausedOrMaxed)
139
139
  end
140
140
  --[[
141
141
  Function to add job considering priority.
142
142
  ]]
143
143
  -- Includes
144
- local function addJobWithPriority(markerKey, prioritizedKey, priority, jobId, priorityCounterKey, isPaused)
144
+ local function addJobWithPriority(markerKey, prioritizedKey, priority, jobId, priorityCounterKey,
145
+ isPausedOrMaxed)
145
146
  local prioCounter = rcall("INCR", priorityCounterKey)
146
147
  local score = priority * 0x100000000 + prioCounter % 0x100000000
147
148
  rcall("ZADD", prioritizedKey, score, jobId)
148
- addBaseMarkerIfNeeded(markerKey, isPaused)
149
+ addBaseMarkerIfNeeded(markerKey, isPausedOrMaxed)
149
150
  end
150
151
  --[[
151
- Function to check for the meta.paused key to decide if we are paused or not
152
+ Function to check if queue is paused or maxed
152
153
  (since an empty list and !EXISTS are not really the same).
153
154
  ]]
154
- local function isQueuePaused(queueMetaKey)
155
- return rcall("HEXISTS", queueMetaKey, "paused") == 1
155
+ local function isQueuePausedOrMaxed(queueMetaKey, activeKey)
156
+ local queueAttributes = rcall("HMGET", queueMetaKey, "paused", "concurrency")
157
+ if queueAttributes[1] then
158
+ return true
159
+ else
160
+ if queueAttributes[2] then
161
+ local activeCount = rcall("LLEN", activeKey)
162
+ return activeCount >= tonumber(queueAttributes[2])
163
+ end
164
+ end
165
+ return false
156
166
  end
157
167
  --[[
158
168
  Function to check for the meta.paused key to decide if we are paused or not
159
169
  (since an empty list and !EXISTS are not really the same).
160
170
  ]]
161
- local function getTargetQueueList(queueMetaKey, waitKey, pausedKey)
162
- if rcall("HEXISTS", queueMetaKey, "paused") ~= 1 then
163
- return waitKey, false
164
- else
171
+ local function getTargetQueueList(queueMetaKey, activeKey, waitKey, pausedKey)
172
+ local queueAttributes = rcall("HMGET", queueMetaKey, "paused", "concurrency")
173
+ if queueAttributes[1] then
165
174
  return pausedKey, true
175
+ else
176
+ if queueAttributes[2] then
177
+ local activeCount = rcall("LLEN", activeKey)
178
+ if activeCount >= tonumber(queueAttributes[2]) then
179
+ return waitKey, true
180
+ else
181
+ return waitKey, false
182
+ end
183
+ end
166
184
  end
185
+ return waitKey, false
167
186
  end
168
187
  local function moveParentToWaitIfNeeded(parentQueueKey, parentDependenciesKey,
169
188
  parentKey, parentId, timestamp)
@@ -173,6 +192,7 @@ local function moveParentToWaitIfNeeded(parentQueueKey, parentDependenciesKey,
173
192
  rcall("ZREM", parentQueueKey .. ":waiting-children", parentId)
174
193
  local parentWaitKey = parentQueueKey .. ":wait"
175
194
  local parentPausedKey = parentQueueKey .. ":paused"
195
+ local parentActiveKey = parentQueueKey .. ":active"
176
196
  local parentMetaKey = parentQueueKey .. ":meta"
177
197
  local parentMarkerKey = parentQueueKey .. ":marker"
178
198
  local jobAttributes = rcall("HMGET", parentKey, "priority", "delay")
@@ -188,15 +208,16 @@ local function moveParentToWaitIfNeeded(parentQueueKey, parentDependenciesKey,
188
208
  addDelayMarkerIfNeeded(parentMarkerKey, parentDelayedKey)
189
209
  else
190
210
  if priority == 0 then
191
- local parentTarget, isParentPaused =
192
- getTargetQueueList(parentMetaKey, parentWaitKey,
211
+ local parentTarget, isParentPausedOrMaxed =
212
+ getTargetQueueList(parentMetaKey, parentActiveKey, parentWaitKey,
193
213
  parentPausedKey)
194
- addJobInTargetList(parentTarget, parentMarkerKey, "RPUSH", isParentPaused, parentId)
214
+ addJobInTargetList(parentTarget, parentMarkerKey, "RPUSH", isParentPausedOrMaxed,
215
+ parentId)
195
216
  else
196
- local isPaused = isQueuePaused(parentMetaKey)
217
+ local isPausedOrMaxed = isQueuePausedOrMaxed(parentMetaKey, parentActiveKey)
197
218
  addJobWithPriority(parentMarkerKey,
198
219
  parentQueueKey .. ":prioritized", priority,
199
- parentId, parentQueueKey .. ":pc", isPaused)
220
+ parentId, parentQueueKey .. ":pc", isPausedOrMaxed)
200
221
  end
201
222
  rcall("XADD", parentQueueKey .. ":events", "*", "event", "waiting",
202
223
  "jobId", parentId, "prev", "waiting-children")
@@ -1 +1 @@
1
- {"version":3,"file":"addDelayedJob-6.js","sourceRoot":"","sources":["../../../src/scripts/addDelayedJob-6.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAmTf,CAAC;AACF,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,IAAI,EAAE,eAAe;IACrB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
1
+ {"version":3,"file":"addDelayedJob-6.js","sourceRoot":"","sources":["../../../src/scripts/addDelayedJob-6.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwUf,CAAC;AACF,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,IAAI,EAAE,eAAe;IACrB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
@@ -100,42 +100,61 @@ end
100
100
  --[[
101
101
  Add marker if needed when a job is available.
102
102
  ]]
103
- local function addBaseMarkerIfNeeded(markerKey, isPaused)
104
- if not isPaused then
103
+ local function addBaseMarkerIfNeeded(markerKey, isPausedOrMaxed)
104
+ if not isPausedOrMaxed then
105
105
  rcall("ZADD", markerKey, 0, "0")
106
106
  end
107
107
  end
108
- local function addJobInTargetList(targetKey, markerKey, pushCmd, isPaused, jobId)
108
+ local function addJobInTargetList(targetKey, markerKey, pushCmd, isPausedOrMaxed, jobId)
109
109
  rcall(pushCmd, targetKey, jobId)
110
- addBaseMarkerIfNeeded(markerKey, isPaused)
110
+ addBaseMarkerIfNeeded(markerKey, isPausedOrMaxed)
111
111
  end
112
112
  --[[
113
113
  Function to add job considering priority.
114
114
  ]]
115
115
  -- Includes
116
- local function addJobWithPriority(markerKey, prioritizedKey, priority, jobId, priorityCounterKey, isPaused)
116
+ local function addJobWithPriority(markerKey, prioritizedKey, priority, jobId, priorityCounterKey,
117
+ isPausedOrMaxed)
117
118
  local prioCounter = rcall("INCR", priorityCounterKey)
118
119
  local score = priority * 0x100000000 + prioCounter % 0x100000000
119
120
  rcall("ZADD", prioritizedKey, score, jobId)
120
- addBaseMarkerIfNeeded(markerKey, isPaused)
121
+ addBaseMarkerIfNeeded(markerKey, isPausedOrMaxed)
121
122
  end
122
123
  --[[
123
- Function to check for the meta.paused key to decide if we are paused or not
124
+ Function to check if queue is paused or maxed
124
125
  (since an empty list and !EXISTS are not really the same).
125
126
  ]]
126
- local function isQueuePaused(queueMetaKey)
127
- return rcall("HEXISTS", queueMetaKey, "paused") == 1
127
+ local function isQueuePausedOrMaxed(queueMetaKey, activeKey)
128
+ local queueAttributes = rcall("HMGET", queueMetaKey, "paused", "concurrency")
129
+ if queueAttributes[1] then
130
+ return true
131
+ else
132
+ if queueAttributes[2] then
133
+ local activeCount = rcall("LLEN", activeKey)
134
+ return activeCount >= tonumber(queueAttributes[2])
135
+ end
136
+ end
137
+ return false
128
138
  end
129
139
  --[[
130
140
  Function to check for the meta.paused key to decide if we are paused or not
131
141
  (since an empty list and !EXISTS are not really the same).
132
142
  ]]
133
- local function getTargetQueueList(queueMetaKey, waitKey, pausedKey)
134
- if rcall("HEXISTS", queueMetaKey, "paused") ~= 1 then
135
- return waitKey, false
136
- else
143
+ local function getTargetQueueList(queueMetaKey, activeKey, waitKey, pausedKey)
144
+ local queueAttributes = rcall("HMGET", queueMetaKey, "paused", "concurrency")
145
+ if queueAttributes[1] then
137
146
  return pausedKey, true
147
+ else
148
+ if queueAttributes[2] then
149
+ local activeCount = rcall("LLEN", activeKey)
150
+ if activeCount >= tonumber(queueAttributes[2]) then
151
+ return waitKey, true
152
+ else
153
+ return waitKey, false
154
+ end
155
+ end
138
156
  end
157
+ return waitKey, false
139
158
  end
140
159
  local function moveParentToWaitIfNeeded(parentQueueKey, parentDependenciesKey,
141
160
  parentKey, parentId, timestamp)
@@ -145,6 +164,7 @@ local function moveParentToWaitIfNeeded(parentQueueKey, parentDependenciesKey,
145
164
  rcall("ZREM", parentQueueKey .. ":waiting-children", parentId)
146
165
  local parentWaitKey = parentQueueKey .. ":wait"
147
166
  local parentPausedKey = parentQueueKey .. ":paused"
167
+ local parentActiveKey = parentQueueKey .. ":active"
148
168
  local parentMetaKey = parentQueueKey .. ":meta"
149
169
  local parentMarkerKey = parentQueueKey .. ":marker"
150
170
  local jobAttributes = rcall("HMGET", parentKey, "priority", "delay")
@@ -160,15 +180,16 @@ local function moveParentToWaitIfNeeded(parentQueueKey, parentDependenciesKey,
160
180
  addDelayMarkerIfNeeded(parentMarkerKey, parentDelayedKey)
161
181
  else
162
182
  if priority == 0 then
163
- local parentTarget, isParentPaused =
164
- getTargetQueueList(parentMetaKey, parentWaitKey,
183
+ local parentTarget, isParentPausedOrMaxed =
184
+ getTargetQueueList(parentMetaKey, parentActiveKey, parentWaitKey,
165
185
  parentPausedKey)
166
- addJobInTargetList(parentTarget, parentMarkerKey, "RPUSH", isParentPaused, parentId)
186
+ addJobInTargetList(parentTarget, parentMarkerKey, "RPUSH", isParentPausedOrMaxed,
187
+ parentId)
167
188
  else
168
- local isPaused = isQueuePaused(parentMetaKey)
189
+ local isPausedOrMaxed = isQueuePausedOrMaxed(parentMetaKey, parentActiveKey)
169
190
  addJobWithPriority(parentMarkerKey,
170
191
  parentQueueKey .. ":prioritized", priority,
171
- parentId, parentQueueKey .. ":pc", isPaused)
192
+ parentId, parentQueueKey .. ":pc", isPausedOrMaxed)
172
193
  end
173
194
  rcall("XADD", parentQueueKey .. ":events", "*", "event", "waiting",
174
195
  "jobId", parentId, "prev", "waiting-children")
@@ -1 +1 @@
1
- {"version":3,"file":"addParentJob-4.js","sourceRoot":"","sources":["../../../src/scripts/addParentJob-4.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkRf,CAAC;AACF,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,IAAI,EAAE,cAAc;IACpB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
1
+ {"version":3,"file":"addParentJob-4.js","sourceRoot":"","sources":["../../../src/scripts/addParentJob-4.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAuSf,CAAC;AACF,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,IAAI,EAAE,cAAc;IACpB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
@@ -9,8 +9,9 @@ const content = `--[[
9
9
  KEYS[3] 'id'
10
10
  KEYS[4] 'prioritized'
11
11
  KEYS[5] 'completed'
12
- KEYS[6] events stream key
13
- KEYS[7] 'pc' priority counter
12
+ KEYS[6] 'active'
13
+ KEYS[7] events stream key
14
+ KEYS[8] 'pc' priority counter
14
15
  ARGV[1] msgpacked arguments array
15
16
  [1] key prefix,
16
17
  [2] custom id (will not generate one automatically)
@@ -31,8 +32,9 @@ local metaKey = KEYS[2]
31
32
  local idKey = KEYS[3]
32
33
  local priorityKey = KEYS[4]
33
34
  local completedKey = KEYS[5]
34
- local eventsKey = KEYS[6]
35
- local priorityCounterKey = KEYS[7]
35
+ local activeKey = KEYS[6]
36
+ local eventsKey = KEYS[7]
37
+ local priorityCounterKey = KEYS[8]
36
38
  local jobId
37
39
  local jobIdKey
38
40
  local rcall = redis.call
@@ -51,16 +53,17 @@ local parentData
51
53
  --[[
52
54
  Add marker if needed when a job is available.
53
55
  ]]
54
- local function addBaseMarkerIfNeeded(markerKey, isPaused)
55
- if not isPaused then
56
+ local function addBaseMarkerIfNeeded(markerKey, isPausedOrMaxed)
57
+ if not isPausedOrMaxed then
56
58
  rcall("ZADD", markerKey, 0, "0")
57
59
  end
58
60
  end
59
- local function addJobWithPriority(markerKey, prioritizedKey, priority, jobId, priorityCounterKey, isPaused)
61
+ local function addJobWithPriority(markerKey, prioritizedKey, priority, jobId, priorityCounterKey,
62
+ isPausedOrMaxed)
60
63
  local prioCounter = rcall("INCR", priorityCounterKey)
61
64
  local score = priority * 0x100000000 + prioCounter % 0x100000000
62
65
  rcall("ZADD", prioritizedKey, score, jobId)
63
- addBaseMarkerIfNeeded(markerKey, isPaused)
66
+ addBaseMarkerIfNeeded(markerKey, isPausedOrMaxed)
64
67
  end
65
68
  --[[
66
69
  Function to store a job
@@ -145,27 +148,45 @@ end
145
148
  Function to add job in target list and add marker if needed.
146
149
  ]]
147
150
  -- Includes
148
- local function addJobInTargetList(targetKey, markerKey, pushCmd, isPaused, jobId)
151
+ local function addJobInTargetList(targetKey, markerKey, pushCmd, isPausedOrMaxed, jobId)
149
152
  rcall(pushCmd, targetKey, jobId)
150
- addBaseMarkerIfNeeded(markerKey, isPaused)
153
+ addBaseMarkerIfNeeded(markerKey, isPausedOrMaxed)
151
154
  end
152
155
  --[[
153
- Function to check for the meta.paused key to decide if we are paused or not
156
+ Function to check if queue is paused or maxed
154
157
  (since an empty list and !EXISTS are not really the same).
155
158
  ]]
156
- local function isQueuePaused(queueMetaKey)
157
- return rcall("HEXISTS", queueMetaKey, "paused") == 1
159
+ local function isQueuePausedOrMaxed(queueMetaKey, activeKey)
160
+ local queueAttributes = rcall("HMGET", queueMetaKey, "paused", "concurrency")
161
+ if queueAttributes[1] then
162
+ return true
163
+ else
164
+ if queueAttributes[2] then
165
+ local activeCount = rcall("LLEN", activeKey)
166
+ return activeCount >= tonumber(queueAttributes[2])
167
+ end
168
+ end
169
+ return false
158
170
  end
159
171
  --[[
160
172
  Function to check for the meta.paused key to decide if we are paused or not
161
173
  (since an empty list and !EXISTS are not really the same).
162
174
  ]]
163
- local function getTargetQueueList(queueMetaKey, waitKey, pausedKey)
164
- if rcall("HEXISTS", queueMetaKey, "paused") ~= 1 then
165
- return waitKey, false
166
- else
175
+ local function getTargetQueueList(queueMetaKey, activeKey, waitKey, pausedKey)
176
+ local queueAttributes = rcall("HMGET", queueMetaKey, "paused", "concurrency")
177
+ if queueAttributes[1] then
167
178
  return pausedKey, true
179
+ else
180
+ if queueAttributes[2] then
181
+ local activeCount = rcall("LLEN", activeKey)
182
+ if activeCount >= tonumber(queueAttributes[2]) then
183
+ return waitKey, true
184
+ else
185
+ return waitKey, false
186
+ end
187
+ end
168
188
  end
189
+ return waitKey, false
169
190
  end
170
191
  local function moveParentToWaitIfNeeded(parentQueueKey, parentDependenciesKey,
171
192
  parentKey, parentId, timestamp)
@@ -175,6 +196,7 @@ local function moveParentToWaitIfNeeded(parentQueueKey, parentDependenciesKey,
175
196
  rcall("ZREM", parentQueueKey .. ":waiting-children", parentId)
176
197
  local parentWaitKey = parentQueueKey .. ":wait"
177
198
  local parentPausedKey = parentQueueKey .. ":paused"
199
+ local parentActiveKey = parentQueueKey .. ":active"
178
200
  local parentMetaKey = parentQueueKey .. ":meta"
179
201
  local parentMarkerKey = parentQueueKey .. ":marker"
180
202
  local jobAttributes = rcall("HMGET", parentKey, "priority", "delay")
@@ -190,15 +212,16 @@ local function moveParentToWaitIfNeeded(parentQueueKey, parentDependenciesKey,
190
212
  addDelayMarkerIfNeeded(parentMarkerKey, parentDelayedKey)
191
213
  else
192
214
  if priority == 0 then
193
- local parentTarget, isParentPaused =
194
- getTargetQueueList(parentMetaKey, parentWaitKey,
215
+ local parentTarget, isParentPausedOrMaxed =
216
+ getTargetQueueList(parentMetaKey, parentActiveKey, parentWaitKey,
195
217
  parentPausedKey)
196
- addJobInTargetList(parentTarget, parentMarkerKey, "RPUSH", isParentPaused, parentId)
218
+ addJobInTargetList(parentTarget, parentMarkerKey, "RPUSH", isParentPausedOrMaxed,
219
+ parentId)
197
220
  else
198
- local isPaused = isQueuePaused(parentMetaKey)
221
+ local isPausedOrMaxed = isQueuePausedOrMaxed(parentMetaKey, parentActiveKey)
199
222
  addJobWithPriority(parentMarkerKey,
200
223
  parentQueueKey .. ":prioritized", priority,
201
- parentId, parentQueueKey .. ":pc", isPaused)
224
+ parentId, parentQueueKey .. ":pc", isPausedOrMaxed)
202
225
  end
203
226
  rcall("XADD", parentQueueKey .. ":events", "*", "event", "waiting",
204
227
  "jobId", parentId, "prev", "waiting-children")
@@ -270,8 +293,8 @@ local delay, priority = storeJob(eventsKey, jobIdKey, jobId, args[3], ARGV[2],
270
293
  opts, timestamp, parentKey, parentData,
271
294
  repeatJobKey)
272
295
  -- Add the job to the prioritized set
273
- local isPause = isQueuePaused(metaKey)
274
- addJobWithPriority( KEYS[1], priorityKey, priority, jobId, priorityCounterKey, isPause)
296
+ local isPausedOrMaxed = isQueuePausedOrMaxed(metaKey, activeKey)
297
+ addJobWithPriority( KEYS[1], priorityKey, priority, jobId, priorityCounterKey, isPausedOrMaxed)
275
298
  -- Emit waiting event
276
299
  rcall("XADD", eventsKey, "MAXLEN", "~", maxEvents, "*", "event", "waiting",
277
300
  "jobId", jobId)
@@ -284,6 +307,6 @@ return jobId .. "" -- convert to string
284
307
  export const addPrioritizedJob = {
285
308
  name: 'addPrioritizedJob',
286
309
  content,
287
- keys: 7,
310
+ keys: 8,
288
311
  };
289
- //# sourceMappingURL=addPrioritizedJob-7.js.map
312
+ //# sourceMappingURL=addPrioritizedJob-8.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"addPrioritizedJob-8.js","sourceRoot":"","sources":["../../../src/scripts/addPrioritizedJob-8.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiTf,CAAC;AACF,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,IAAI,EAAE,mBAAmB;IACzB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
@@ -0,0 +1,5 @@
1
+ export declare const addRepeatableJob: {
2
+ name: string;
3
+ content: string;
4
+ keys: number;
5
+ };
@@ -0,0 +1,63 @@
1
+ const content = `--[[
2
+ Adds a repeatable job
3
+ Input:
4
+ KEYS[1] 'repeat' key
5
+ KEYS[2] custom key
6
+ ARGV[1] next milliseconds
7
+ ARGV[2] msgpacked options
8
+ [1] name
9
+ [2] tz?
10
+ [3] patten?
11
+ [4] endDate?
12
+ [5] every?
13
+ ARGV[3] legacy custom key TODO: remove this logic in next breaking change
14
+ ARGV[4] skipCheckExists
15
+ Output:
16
+ repeatableKey - OK
17
+ ]]
18
+ local rcall = redis.call
19
+ local repeatKey = KEYS[1]
20
+ local customKey = KEYS[2]
21
+ local legacyCustomKey = ARGV[3]
22
+ local nextMilli = ARGV[1]
23
+ local function storeRepeatableJob(repeatKey, customKey, nextMilli, rawOpts)
24
+ rcall("ZADD", repeatKey, nextMilli, customKey)
25
+ local opts = cmsgpack.unpack(rawOpts)
26
+ local optionalValues = {}
27
+ if opts['tz'] then
28
+ table.insert(optionalValues, "tz")
29
+ table.insert(optionalValues, opts['tz'])
30
+ end
31
+ if opts['pattern'] then
32
+ table.insert(optionalValues, "pattern")
33
+ table.insert(optionalValues, opts['pattern'])
34
+ end
35
+ if opts['endDate'] then
36
+ table.insert(optionalValues, "endDate")
37
+ table.insert(optionalValues, opts['endDate'])
38
+ end
39
+ if opts['every'] then
40
+ table.insert(optionalValues, "every")
41
+ table.insert(optionalValues, opts['every'])
42
+ end
43
+ rcall("HMSET", repeatKey .. ":" .. customKey, "name", opts['name'],
44
+ unpack(optionalValues))
45
+ return customKey
46
+ end
47
+ if ARGV[4] == '0' then
48
+ if rcall("ZSCORE", repeatKey, legacyCustomKey) ~= false then
49
+ rcall("ZADD", repeatKey, nextMilli, legacyCustomKey)
50
+ return legacyCustomKey
51
+ elseif rcall("ZSCORE", repeatKey, customKey) ~= false then
52
+ return storeRepeatableJob(repeatKey, customKey, nextMilli, ARGV[2])
53
+ end
54
+ else
55
+ return storeRepeatableJob(repeatKey, customKey, nextMilli, ARGV[2])
56
+ end
57
+ return ''`;
58
+ export const addRepeatableJob = {
59
+ name: 'addRepeatableJob',
60
+ content,
61
+ keys: 2,
62
+ };
63
+ //# sourceMappingURL=addRepeatableJob-2.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"addRepeatableJob-2.js","sourceRoot":"","sources":["../../../src/scripts/addRepeatableJob-2.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UAwDN,CAAC;AACX,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,IAAI,EAAE,kBAAkB;IACxB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
@@ -18,8 +18,9 @@ const content = `--[[
18
18
  KEYS[3] 'meta'
19
19
  KEYS[4] 'id'
20
20
  KEYS[5] 'completed'
21
- KEYS[6] events stream key
22
- KEYS[7] marker key
21
+ KEYS[6] 'active'
22
+ KEYS[7] events stream key
23
+ KEYS[8] marker key
23
24
  ARGV[1] msgpacked arguments array
24
25
  [1] key prefix,
25
26
  [2] custom id (will not generate one automatically)
@@ -36,7 +37,7 @@ const content = `--[[
36
37
  jobId - OK
37
38
  -5 - Missing parent key
38
39
  ]]
39
- local eventsKey = KEYS[6]
40
+ local eventsKey = KEYS[7]
40
41
  local jobId
41
42
  local jobIdKey
42
43
  local rcall = redis.call
@@ -55,14 +56,14 @@ local parentData
55
56
  --[[
56
57
  Add marker if needed when a job is available.
57
58
  ]]
58
- local function addBaseMarkerIfNeeded(markerKey, isPaused)
59
- if not isPaused then
59
+ local function addBaseMarkerIfNeeded(markerKey, isPausedOrMaxed)
60
+ if not isPausedOrMaxed then
60
61
  rcall("ZADD", markerKey, 0, "0")
61
62
  end
62
63
  end
63
- local function addJobInTargetList(targetKey, markerKey, pushCmd, isPaused, jobId)
64
+ local function addJobInTargetList(targetKey, markerKey, pushCmd, isPausedOrMaxed, jobId)
64
65
  rcall(pushCmd, targetKey, jobId)
65
- addBaseMarkerIfNeeded(markerKey, isPaused)
66
+ addBaseMarkerIfNeeded(markerKey, isPausedOrMaxed)
66
67
  end
67
68
  --[[
68
69
  Function to get max events value or set by default 10000.
@@ -79,12 +80,21 @@ end
79
80
  Function to check for the meta.paused key to decide if we are paused or not
80
81
  (since an empty list and !EXISTS are not really the same).
81
82
  ]]
82
- local function getTargetQueueList(queueMetaKey, waitKey, pausedKey)
83
- if rcall("HEXISTS", queueMetaKey, "paused") ~= 1 then
84
- return waitKey, false
85
- else
83
+ local function getTargetQueueList(queueMetaKey, activeKey, waitKey, pausedKey)
84
+ local queueAttributes = rcall("HMGET", queueMetaKey, "paused", "concurrency")
85
+ if queueAttributes[1] then
86
86
  return pausedKey, true
87
+ else
88
+ if queueAttributes[2] then
89
+ local activeCount = rcall("LLEN", activeKey)
90
+ if activeCount >= tonumber(queueAttributes[2]) then
91
+ return waitKey, true
92
+ else
93
+ return waitKey, false
94
+ end
95
+ end
87
96
  end
97
+ return waitKey, false
88
98
  end
89
99
  --[[
90
100
  Function to handle the case when job is duplicated.
@@ -133,18 +143,28 @@ end
133
143
  Function to add job considering priority.
134
144
  ]]
135
145
  -- Includes
136
- local function addJobWithPriority(markerKey, prioritizedKey, priority, jobId, priorityCounterKey, isPaused)
146
+ local function addJobWithPriority(markerKey, prioritizedKey, priority, jobId, priorityCounterKey,
147
+ isPausedOrMaxed)
137
148
  local prioCounter = rcall("INCR", priorityCounterKey)
138
149
  local score = priority * 0x100000000 + prioCounter % 0x100000000
139
150
  rcall("ZADD", prioritizedKey, score, jobId)
140
- addBaseMarkerIfNeeded(markerKey, isPaused)
151
+ addBaseMarkerIfNeeded(markerKey, isPausedOrMaxed)
141
152
  end
142
153
  --[[
143
- Function to check for the meta.paused key to decide if we are paused or not
154
+ Function to check if queue is paused or maxed
144
155
  (since an empty list and !EXISTS are not really the same).
145
156
  ]]
146
- local function isQueuePaused(queueMetaKey)
147
- return rcall("HEXISTS", queueMetaKey, "paused") == 1
157
+ local function isQueuePausedOrMaxed(queueMetaKey, activeKey)
158
+ local queueAttributes = rcall("HMGET", queueMetaKey, "paused", "concurrency")
159
+ if queueAttributes[1] then
160
+ return true
161
+ else
162
+ if queueAttributes[2] then
163
+ local activeCount = rcall("LLEN", activeKey)
164
+ return activeCount >= tonumber(queueAttributes[2])
165
+ end
166
+ end
167
+ return false
148
168
  end
149
169
  local function moveParentToWaitIfNeeded(parentQueueKey, parentDependenciesKey,
150
170
  parentKey, parentId, timestamp)
@@ -154,6 +174,7 @@ local function moveParentToWaitIfNeeded(parentQueueKey, parentDependenciesKey,
154
174
  rcall("ZREM", parentQueueKey .. ":waiting-children", parentId)
155
175
  local parentWaitKey = parentQueueKey .. ":wait"
156
176
  local parentPausedKey = parentQueueKey .. ":paused"
177
+ local parentActiveKey = parentQueueKey .. ":active"
157
178
  local parentMetaKey = parentQueueKey .. ":meta"
158
179
  local parentMarkerKey = parentQueueKey .. ":marker"
159
180
  local jobAttributes = rcall("HMGET", parentKey, "priority", "delay")
@@ -169,15 +190,16 @@ local function moveParentToWaitIfNeeded(parentQueueKey, parentDependenciesKey,
169
190
  addDelayMarkerIfNeeded(parentMarkerKey, parentDelayedKey)
170
191
  else
171
192
  if priority == 0 then
172
- local parentTarget, isParentPaused =
173
- getTargetQueueList(parentMetaKey, parentWaitKey,
193
+ local parentTarget, isParentPausedOrMaxed =
194
+ getTargetQueueList(parentMetaKey, parentActiveKey, parentWaitKey,
174
195
  parentPausedKey)
175
- addJobInTargetList(parentTarget, parentMarkerKey, "RPUSH", isParentPaused, parentId)
196
+ addJobInTargetList(parentTarget, parentMarkerKey, "RPUSH", isParentPausedOrMaxed,
197
+ parentId)
176
198
  else
177
- local isPaused = isQueuePaused(parentMetaKey)
199
+ local isPausedOrMaxed = isQueuePausedOrMaxed(parentMetaKey, parentActiveKey)
178
200
  addJobWithPriority(parentMarkerKey,
179
201
  parentQueueKey .. ":prioritized", priority,
180
- parentId, parentQueueKey .. ":pc", isPaused)
202
+ parentId, parentQueueKey .. ":pc", isPausedOrMaxed)
181
203
  end
182
204
  rcall("XADD", parentQueueKey .. ":events", "*", "event", "waiting",
183
205
  "jobId", parentId, "prev", "waiting-children")
@@ -273,10 +295,10 @@ end
273
295
  -- Store the job.
274
296
  storeJob(eventsKey, jobIdKey, jobId, args[3], ARGV[2], opts, timestamp,
275
297
  parentKey, parentData, repeatJobKey)
276
- local target, paused = getTargetQueueList(metaKey, KEYS[1], KEYS[2])
298
+ local target, isPausedOrMaxed = getTargetQueueList(metaKey, KEYS[6], KEYS[1], KEYS[2])
277
299
  -- LIFO or FIFO
278
300
  local pushCmd = opts['lifo'] and 'RPUSH' or 'LPUSH'
279
- addJobInTargetList(target, KEYS[7], pushCmd, paused, jobId)
301
+ addJobInTargetList(target, KEYS[8], pushCmd, isPausedOrMaxed, jobId)
280
302
  -- Emit waiting event
281
303
  rcall("XADD", eventsKey, "MAXLEN", "~", maxEvents, "*", "event", "waiting",
282
304
  "jobId", jobId)
@@ -289,6 +311,6 @@ return jobId .. "" -- convert to string
289
311
  export const addStandardJob = {
290
312
  name: 'addStandardJob',
291
313
  content,
292
- keys: 7,
314
+ keys: 8,
293
315
  };
294
- //# sourceMappingURL=addStandardJob-7.js.map
316
+ //# sourceMappingURL=addStandardJob-8.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"addStandardJob-8.js","sourceRoot":"","sources":["../../../src/scripts/addStandardJob-8.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAqTf,CAAC;AACF,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,IAAI,EAAE,gBAAgB;IACtB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}