bullmq 5.8.6 → 5.9.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 (188) 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/scripts.js +17 -1
  4. package/dist/cjs/classes/scripts.js.map +1 -1
  5. package/dist/cjs/classes/worker.js +1 -1
  6. package/dist/cjs/classes/worker.js.map +1 -1
  7. package/dist/cjs/commands/addDelayedJob-6.lua +2 -6
  8. package/dist/cjs/commands/{addPrioritizedJob-7.lua → addPrioritizedJob-8.lua} +9 -7
  9. package/dist/cjs/commands/{addStandardJob-7.lua → addStandardJob-8.lua} +6 -5
  10. package/dist/cjs/commands/changeDelay-4.lua +1 -5
  11. package/dist/cjs/commands/{changePriority-6.lua → changePriority-7.lua} +12 -10
  12. package/dist/cjs/commands/getCountsPerPriority-4.lua +6 -3
  13. package/dist/cjs/commands/includes/addBaseMarkerIfNeeded.lua +2 -2
  14. package/dist/cjs/commands/includes/addJobInTargetList.lua +2 -2
  15. package/dist/cjs/commands/includes/addJobWithPriority.lua +3 -2
  16. package/dist/cjs/commands/includes/getTargetQueueList.lua +14 -4
  17. package/dist/cjs/commands/includes/isQueueMaxed.lua +15 -0
  18. package/dist/cjs/commands/includes/isQueuePaused.lua +1 -1
  19. package/dist/cjs/commands/includes/isQueuePausedOrMaxed.lua +18 -0
  20. package/dist/cjs/commands/includes/moveParentToWaitIfNeeded.lua +8 -6
  21. package/dist/cjs/commands/includes/removeParentDependencyKey.lua +3 -3
  22. package/dist/cjs/commands/isMaxed-2.lua +17 -0
  23. package/dist/cjs/commands/moveJobFromActiveToWait-10.lua +2 -2
  24. package/dist/{esm/commands/moveJobsToWait-7.lua → cjs/commands/moveJobsToWait-8.lua} +4 -3
  25. package/dist/cjs/commands/moveStalledJobsToWait-9.lua +3 -3
  26. package/dist/cjs/commands/moveToActive-11.lua +4 -4
  27. package/dist/cjs/commands/moveToDelayed-8.lua +2 -6
  28. package/dist/cjs/commands/moveToFinished-14.lua +4 -4
  29. package/dist/cjs/commands/moveToWaitingChildren-5.lua +4 -3
  30. package/dist/{esm/commands/promote-8.lua → cjs/commands/promote-9.lua} +9 -7
  31. package/dist/{esm/commands/removeJob-1.lua → cjs/commands/removeJob-2.lua} +2 -1
  32. package/dist/{esm/commands/reprocessJob-7.lua → cjs/commands/reprocessJob-8.lua} +4 -3
  33. package/dist/cjs/commands/retryJob-11.lua +8 -4
  34. package/dist/cjs/scripts/addDelayedJob-6.js +41 -23
  35. package/dist/cjs/scripts/addDelayedJob-6.js.map +1 -1
  36. package/dist/cjs/scripts/addParentJob-4.js +39 -18
  37. package/dist/cjs/scripts/addParentJob-4.js.map +1 -1
  38. package/dist/cjs/scripts/{addPrioritizedJob-7.js → addPrioritizedJob-8.js} +49 -26
  39. package/dist/cjs/scripts/addPrioritizedJob-8.js.map +1 -0
  40. package/dist/cjs/scripts/{addStandardJob-7.js → addStandardJob-8.js} +47 -25
  41. package/dist/cjs/scripts/addStandardJob-8.js.map +1 -0
  42. package/dist/cjs/scripts/changeDelay-4.js +1 -11
  43. package/dist/cjs/scripts/changeDelay-4.js.map +1 -1
  44. package/dist/cjs/scripts/{changePriority-6.js → changePriority-7.js} +33 -21
  45. package/dist/cjs/scripts/changePriority-7.js.map +1 -0
  46. package/dist/cjs/scripts/cleanJobsInSet-2.js +20 -11
  47. package/dist/cjs/scripts/cleanJobsInSet-2.js.map +1 -1
  48. package/dist/cjs/scripts/drain-4.js +20 -11
  49. package/dist/cjs/scripts/drain-4.js.map +1 -1
  50. package/dist/cjs/scripts/getCountsPerPriority-4.js +7 -8
  51. package/dist/cjs/scripts/getCountsPerPriority-4.js.map +1 -1
  52. package/dist/cjs/scripts/index.js +8 -7
  53. package/dist/cjs/scripts/index.js.map +1 -1
  54. package/dist/cjs/scripts/isMaxed-2.js +34 -0
  55. package/dist/cjs/scripts/isMaxed-2.js.map +1 -0
  56. package/dist/cjs/scripts/moveJobFromActiveToWait-10.js +19 -10
  57. package/dist/cjs/scripts/moveJobFromActiveToWait-10.js.map +1 -1
  58. package/dist/cjs/scripts/{moveJobsToWait-7.js → moveJobsToWait-8.js} +21 -11
  59. package/dist/cjs/scripts/moveJobsToWait-8.js.map +1 -0
  60. package/dist/cjs/scripts/moveStalledJobsToWait-9.js +45 -24
  61. package/dist/cjs/scripts/moveStalledJobsToWait-9.js.map +1 -1
  62. package/dist/cjs/scripts/moveToActive-11.js +24 -14
  63. package/dist/cjs/scripts/moveToActive-11.js.map +1 -1
  64. package/dist/cjs/scripts/moveToDelayed-8.js +2 -12
  65. package/dist/cjs/scripts/moveToDelayed-8.js.map +1 -1
  66. package/dist/cjs/scripts/moveToFinished-14.js +46 -25
  67. package/dist/cjs/scripts/moveToFinished-14.js.map +1 -1
  68. package/dist/cjs/scripts/moveToWaitingChildren-5.js +4 -3
  69. package/dist/cjs/scripts/moveToWaitingChildren-5.js.map +1 -1
  70. package/dist/cjs/scripts/obliterate-2.js +20 -11
  71. package/dist/cjs/scripts/obliterate-2.js.map +1 -1
  72. package/dist/cjs/scripts/{promote-8.js → promote-9.js} +31 -19
  73. package/dist/cjs/scripts/promote-9.js.map +1 -0
  74. package/dist/cjs/scripts/removeChildDependency-1.js +20 -11
  75. package/dist/cjs/scripts/removeChildDependency-1.js.map +1 -1
  76. package/dist/cjs/scripts/{removeJob-1.js → removeJob-2.js} +24 -14
  77. package/dist/cjs/scripts/{removeJob-1.js.map → removeJob-2.js.map} +1 -1
  78. package/dist/cjs/scripts/{reprocessJob-7.js → reprocessJob-8.js} +23 -13
  79. package/dist/cjs/scripts/reprocessJob-8.js.map +1 -0
  80. package/dist/cjs/scripts/retryJob-11.js +42 -14
  81. package/dist/cjs/scripts/retryJob-11.js.map +1 -1
  82. package/dist/cjs/tsconfig-cjs.tsbuildinfo +1 -1
  83. package/dist/esm/classes/queue.d.ts +17 -0
  84. package/dist/esm/classes/queue.js +29 -0
  85. package/dist/esm/classes/queue.js.map +1 -1
  86. package/dist/esm/classes/scripts.d.ts +2 -0
  87. package/dist/esm/classes/scripts.js +17 -1
  88. package/dist/esm/classes/scripts.js.map +1 -1
  89. package/dist/esm/classes/worker.js +1 -1
  90. package/dist/esm/classes/worker.js.map +1 -1
  91. package/dist/esm/commands/addDelayedJob-6.lua +2 -6
  92. package/dist/esm/commands/{addPrioritizedJob-7.lua → addPrioritizedJob-8.lua} +9 -7
  93. package/dist/esm/commands/{addStandardJob-7.lua → addStandardJob-8.lua} +6 -5
  94. package/dist/esm/commands/changeDelay-4.lua +1 -5
  95. package/dist/esm/commands/{changePriority-6.lua → changePriority-7.lua} +12 -10
  96. package/dist/esm/commands/getCountsPerPriority-4.lua +6 -3
  97. package/dist/esm/commands/includes/addBaseMarkerIfNeeded.lua +2 -2
  98. package/dist/esm/commands/includes/addJobInTargetList.lua +2 -2
  99. package/dist/esm/commands/includes/addJobWithPriority.lua +3 -2
  100. package/dist/esm/commands/includes/getTargetQueueList.lua +14 -4
  101. package/dist/esm/commands/includes/isQueueMaxed.lua +15 -0
  102. package/dist/esm/commands/includes/isQueuePaused.lua +1 -1
  103. package/dist/esm/commands/includes/isQueuePausedOrMaxed.lua +18 -0
  104. package/dist/esm/commands/includes/moveParentToWaitIfNeeded.lua +8 -6
  105. package/dist/esm/commands/includes/removeParentDependencyKey.lua +3 -3
  106. package/dist/esm/commands/isMaxed-2.lua +17 -0
  107. package/dist/esm/commands/moveJobFromActiveToWait-10.lua +2 -2
  108. package/dist/{cjs/commands/moveJobsToWait-7.lua → esm/commands/moveJobsToWait-8.lua} +4 -3
  109. package/dist/esm/commands/moveStalledJobsToWait-9.lua +3 -3
  110. package/dist/esm/commands/moveToActive-11.lua +4 -4
  111. package/dist/esm/commands/moveToDelayed-8.lua +2 -6
  112. package/dist/esm/commands/moveToFinished-14.lua +4 -4
  113. package/dist/esm/commands/moveToWaitingChildren-5.lua +4 -3
  114. package/dist/{cjs/commands/promote-8.lua → esm/commands/promote-9.lua} +9 -7
  115. package/dist/{cjs/commands/removeJob-1.lua → esm/commands/removeJob-2.lua} +2 -1
  116. package/dist/{cjs/commands/reprocessJob-7.lua → esm/commands/reprocessJob-8.lua} +4 -3
  117. package/dist/esm/commands/retryJob-11.lua +8 -4
  118. package/dist/esm/scripts/addDelayedJob-6.js +41 -23
  119. package/dist/esm/scripts/addDelayedJob-6.js.map +1 -1
  120. package/dist/esm/scripts/addParentJob-4.js +39 -18
  121. package/dist/esm/scripts/addParentJob-4.js.map +1 -1
  122. package/dist/esm/scripts/{addPrioritizedJob-7.js → addPrioritizedJob-8.js} +49 -26
  123. package/dist/esm/scripts/addPrioritizedJob-8.js.map +1 -0
  124. package/dist/esm/scripts/{addStandardJob-7.js → addStandardJob-8.js} +47 -25
  125. package/dist/esm/scripts/addStandardJob-8.js.map +1 -0
  126. package/dist/esm/scripts/changeDelay-4.js +1 -11
  127. package/dist/esm/scripts/changeDelay-4.js.map +1 -1
  128. package/dist/esm/scripts/{changePriority-6.js → changePriority-7.js} +33 -21
  129. package/dist/esm/scripts/changePriority-7.js.map +1 -0
  130. package/dist/esm/scripts/cleanJobsInSet-2.js +20 -11
  131. package/dist/esm/scripts/cleanJobsInSet-2.js.map +1 -1
  132. package/dist/esm/scripts/drain-4.js +20 -11
  133. package/dist/esm/scripts/drain-4.js.map +1 -1
  134. package/dist/esm/scripts/getCountsPerPriority-4.js +7 -8
  135. package/dist/esm/scripts/getCountsPerPriority-4.js.map +1 -1
  136. package/dist/esm/scripts/index.d.ts +8 -7
  137. package/dist/esm/scripts/index.js +8 -7
  138. package/dist/esm/scripts/index.js.map +1 -1
  139. package/dist/esm/scripts/isMaxed-2.d.ts +5 -0
  140. package/dist/esm/scripts/isMaxed-2.js +31 -0
  141. package/dist/esm/scripts/isMaxed-2.js.map +1 -0
  142. package/dist/esm/scripts/moveJobFromActiveToWait-10.js +19 -10
  143. package/dist/esm/scripts/moveJobFromActiveToWait-10.js.map +1 -1
  144. package/dist/esm/scripts/{moveJobsToWait-7.js → moveJobsToWait-8.js} +21 -11
  145. package/dist/esm/scripts/moveJobsToWait-8.js.map +1 -0
  146. package/dist/esm/scripts/moveStalledJobsToWait-9.js +45 -24
  147. package/dist/esm/scripts/moveStalledJobsToWait-9.js.map +1 -1
  148. package/dist/esm/scripts/moveToActive-11.js +24 -14
  149. package/dist/esm/scripts/moveToActive-11.js.map +1 -1
  150. package/dist/esm/scripts/moveToDelayed-8.js +2 -12
  151. package/dist/esm/scripts/moveToDelayed-8.js.map +1 -1
  152. package/dist/esm/scripts/moveToFinished-14.js +46 -25
  153. package/dist/esm/scripts/moveToFinished-14.js.map +1 -1
  154. package/dist/esm/scripts/moveToWaitingChildren-5.js +4 -3
  155. package/dist/esm/scripts/moveToWaitingChildren-5.js.map +1 -1
  156. package/dist/esm/scripts/obliterate-2.js +20 -11
  157. package/dist/esm/scripts/obliterate-2.js.map +1 -1
  158. package/dist/esm/scripts/{promote-8.js → promote-9.js} +31 -19
  159. package/dist/esm/scripts/promote-9.js.map +1 -0
  160. package/dist/esm/scripts/removeChildDependency-1.js +20 -11
  161. package/dist/esm/scripts/removeChildDependency-1.js.map +1 -1
  162. package/dist/esm/scripts/{removeJob-1.js → removeJob-2.js} +24 -14
  163. package/dist/esm/scripts/{removeJob-1.js.map → removeJob-2.js.map} +1 -1
  164. package/dist/esm/scripts/{reprocessJob-7.js → reprocessJob-8.js} +23 -13
  165. package/dist/esm/scripts/reprocessJob-8.js.map +1 -0
  166. package/dist/esm/scripts/retryJob-11.js +42 -14
  167. package/dist/esm/scripts/retryJob-11.js.map +1 -1
  168. package/dist/esm/tsconfig.tsbuildinfo +1 -1
  169. package/package.json +2 -1
  170. package/dist/cjs/scripts/addPrioritizedJob-7.js.map +0 -1
  171. package/dist/cjs/scripts/addStandardJob-7.js.map +0 -1
  172. package/dist/cjs/scripts/changePriority-6.js.map +0 -1
  173. package/dist/cjs/scripts/moveJobsToWait-7.js.map +0 -1
  174. package/dist/cjs/scripts/promote-8.js.map +0 -1
  175. package/dist/cjs/scripts/reprocessJob-7.js.map +0 -1
  176. package/dist/esm/scripts/addPrioritizedJob-7.js.map +0 -1
  177. package/dist/esm/scripts/addStandardJob-7.js.map +0 -1
  178. package/dist/esm/scripts/changePriority-6.js.map +0 -1
  179. package/dist/esm/scripts/moveJobsToWait-7.js.map +0 -1
  180. package/dist/esm/scripts/promote-8.js.map +0 -1
  181. package/dist/esm/scripts/reprocessJob-7.js.map +0 -1
  182. /package/dist/esm/scripts/{addPrioritizedJob-7.d.ts → addPrioritizedJob-8.d.ts} +0 -0
  183. /package/dist/esm/scripts/{addStandardJob-7.d.ts → addStandardJob-8.d.ts} +0 -0
  184. /package/dist/esm/scripts/{changePriority-6.d.ts → changePriority-7.d.ts} +0 -0
  185. /package/dist/esm/scripts/{moveJobsToWait-7.d.ts → moveJobsToWait-8.d.ts} +0 -0
  186. /package/dist/esm/scripts/{promote-8.d.ts → promote-9.d.ts} +0 -0
  187. /package/dist/esm/scripts/{removeJob-1.d.ts → removeJob-2.d.ts} +0 -0
  188. /package/dist/esm/scripts/{reprocessJob-7.d.ts → reprocessJob-8.d.ts} +0 -0
@@ -103,42 +103,61 @@ end
103
103
  --[[
104
104
  Add marker if needed when a job is available.
105
105
  ]]
106
- local function addBaseMarkerIfNeeded(markerKey, isPaused)
107
- if not isPaused then
106
+ local function addBaseMarkerIfNeeded(markerKey, isPausedOrMaxed)
107
+ if not isPausedOrMaxed then
108
108
  rcall("ZADD", markerKey, 0, "0")
109
109
  end
110
110
  end
111
- local function addJobInTargetList(targetKey, markerKey, pushCmd, isPaused, jobId)
111
+ local function addJobInTargetList(targetKey, markerKey, pushCmd, isPausedOrMaxed, jobId)
112
112
  rcall(pushCmd, targetKey, jobId)
113
- addBaseMarkerIfNeeded(markerKey, isPaused)
113
+ addBaseMarkerIfNeeded(markerKey, isPausedOrMaxed)
114
114
  end
115
115
  --[[
116
116
  Function to add job considering priority.
117
117
  ]]
118
118
  -- Includes
119
- local function addJobWithPriority(markerKey, prioritizedKey, priority, jobId, priorityCounterKey, isPaused)
119
+ local function addJobWithPriority(markerKey, prioritizedKey, priority, jobId, priorityCounterKey,
120
+ isPausedOrMaxed)
120
121
  local prioCounter = rcall("INCR", priorityCounterKey)
121
122
  local score = priority * 0x100000000 + prioCounter % 0x100000000
122
123
  rcall("ZADD", prioritizedKey, score, jobId)
123
- addBaseMarkerIfNeeded(markerKey, isPaused)
124
+ addBaseMarkerIfNeeded(markerKey, isPausedOrMaxed)
124
125
  end
125
126
  --[[
126
- Function to check for the meta.paused key to decide if we are paused or not
127
+ Function to check if queue is paused or maxed
127
128
  (since an empty list and !EXISTS are not really the same).
128
129
  ]]
129
- local function isQueuePaused(queueMetaKey)
130
- return rcall("HEXISTS", queueMetaKey, "paused") == 1
130
+ local function isQueuePausedOrMaxed(queueMetaKey, activeKey)
131
+ local queueAttributes = rcall("HMGET", queueMetaKey, "paused", "concurrency")
132
+ if queueAttributes[1] then
133
+ return true
134
+ else
135
+ if queueAttributes[2] then
136
+ local activeCount = rcall("LLEN", activeKey)
137
+ return activeCount >= tonumber(queueAttributes[2])
138
+ end
139
+ end
140
+ return false
131
141
  end
132
142
  --[[
133
143
  Function to check for the meta.paused key to decide if we are paused or not
134
144
  (since an empty list and !EXISTS are not really the same).
135
145
  ]]
136
- local function getTargetQueueList(queueMetaKey, waitKey, pausedKey)
137
- if rcall("HEXISTS", queueMetaKey, "paused") ~= 1 then
138
- return waitKey, false
139
- else
146
+ local function getTargetQueueList(queueMetaKey, activeKey, waitKey, pausedKey)
147
+ local queueAttributes = rcall("HMGET", queueMetaKey, "paused", "concurrency")
148
+ if queueAttributes[1] then
140
149
  return pausedKey, true
150
+ else
151
+ if queueAttributes[2] then
152
+ local activeCount = rcall("LLEN", activeKey)
153
+ if activeCount >= tonumber(queueAttributes[2]) then
154
+ return waitKey, true
155
+ else
156
+ return waitKey, false
157
+ end
158
+ end
141
159
  end
160
+ return waitKey, false
142
161
  end
143
162
  local function moveParentToWaitIfNeeded(parentQueueKey, parentDependenciesKey,
144
163
  parentKey, parentId, timestamp)
@@ -148,6 +167,7 @@ local function moveParentToWaitIfNeeded(parentQueueKey, parentDependenciesKey,
148
167
  rcall("ZREM", parentQueueKey .. ":waiting-children", parentId)
149
168
  local parentWaitKey = parentQueueKey .. ":wait"
150
169
  local parentPausedKey = parentQueueKey .. ":paused"
170
+ local parentActiveKey = parentQueueKey .. ":active"
151
171
  local parentMetaKey = parentQueueKey .. ":meta"
152
172
  local parentMarkerKey = parentQueueKey .. ":marker"
153
173
  local jobAttributes = rcall("HMGET", parentKey, "priority", "delay")
@@ -163,15 +183,16 @@ local function moveParentToWaitIfNeeded(parentQueueKey, parentDependenciesKey,
163
183
  addDelayMarkerIfNeeded(parentMarkerKey, parentDelayedKey)
164
184
  else
165
185
  if priority == 0 then
166
- local parentTarget, isParentPaused =
167
- getTargetQueueList(parentMetaKey, parentWaitKey,
186
+ local parentTarget, isParentPausedOrMaxed =
187
+ getTargetQueueList(parentMetaKey, parentActiveKey, parentWaitKey,
168
188
  parentPausedKey)
169
- addJobInTargetList(parentTarget, parentMarkerKey, "RPUSH", isParentPaused, parentId)
189
+ addJobInTargetList(parentTarget, parentMarkerKey, "RPUSH", isParentPausedOrMaxed,
190
+ parentId)
170
191
  else
171
- local isPaused = isQueuePaused(parentMetaKey)
192
+ local isPausedOrMaxed = isQueuePausedOrMaxed(parentMetaKey, parentActiveKey)
172
193
  addJobWithPriority(parentMarkerKey,
173
194
  parentQueueKey .. ":prioritized", priority,
174
- parentId, parentQueueKey .. ":pc", isPaused)
195
+ parentId, parentQueueKey .. ":pc", isPausedOrMaxed)
175
196
  end
176
197
  rcall("XADD", parentQueueKey .. ":events", "*", "event", "waiting",
177
198
  "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;AACW,QAAA,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;AACW,QAAA,YAAY,GAAG;IAC1B,IAAI,EAAE,cAAc;IACpB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
@@ -12,8 +12,9 @@ const content = `--[[
12
12
  KEYS[3] 'id'
13
13
  KEYS[4] 'prioritized'
14
14
  KEYS[5] 'completed'
15
- KEYS[6] events stream key
16
- KEYS[7] 'pc' priority counter
15
+ KEYS[6] 'active'
16
+ KEYS[7] events stream key
17
+ KEYS[8] 'pc' priority counter
17
18
  ARGV[1] msgpacked arguments array
18
19
  [1] key prefix,
19
20
  [2] custom id (will not generate one automatically)
@@ -34,8 +35,9 @@ local metaKey = KEYS[2]
34
35
  local idKey = KEYS[3]
35
36
  local priorityKey = KEYS[4]
36
37
  local completedKey = KEYS[5]
37
- local eventsKey = KEYS[6]
38
- local priorityCounterKey = KEYS[7]
38
+ local activeKey = KEYS[6]
39
+ local eventsKey = KEYS[7]
40
+ local priorityCounterKey = KEYS[8]
39
41
  local jobId
40
42
  local jobIdKey
41
43
  local rcall = redis.call
@@ -54,16 +56,17 @@ local parentData
54
56
  --[[
55
57
  Add marker if needed when a job is available.
56
58
  ]]
57
- local function addBaseMarkerIfNeeded(markerKey, isPaused)
58
- if not isPaused then
59
+ local function addBaseMarkerIfNeeded(markerKey, isPausedOrMaxed)
60
+ if not isPausedOrMaxed then
59
61
  rcall("ZADD", markerKey, 0, "0")
60
62
  end
61
63
  end
62
- local function addJobWithPriority(markerKey, prioritizedKey, priority, jobId, priorityCounterKey, isPaused)
64
+ local function addJobWithPriority(markerKey, prioritizedKey, priority, jobId, priorityCounterKey,
65
+ isPausedOrMaxed)
63
66
  local prioCounter = rcall("INCR", priorityCounterKey)
64
67
  local score = priority * 0x100000000 + prioCounter % 0x100000000
65
68
  rcall("ZADD", prioritizedKey, score, jobId)
66
- addBaseMarkerIfNeeded(markerKey, isPaused)
69
+ addBaseMarkerIfNeeded(markerKey, isPausedOrMaxed)
67
70
  end
68
71
  --[[
69
72
  Function to store a job
@@ -148,27 +151,45 @@ end
148
151
  Function to add job in target list and add marker if needed.
149
152
  ]]
150
153
  -- Includes
151
- local function addJobInTargetList(targetKey, markerKey, pushCmd, isPaused, jobId)
154
+ local function addJobInTargetList(targetKey, markerKey, pushCmd, isPausedOrMaxed, jobId)
152
155
  rcall(pushCmd, targetKey, jobId)
153
- addBaseMarkerIfNeeded(markerKey, isPaused)
156
+ addBaseMarkerIfNeeded(markerKey, isPausedOrMaxed)
154
157
  end
155
158
  --[[
156
- Function to check for the meta.paused key to decide if we are paused or not
159
+ Function to check if queue is paused or maxed
157
160
  (since an empty list and !EXISTS are not really the same).
158
161
  ]]
159
- local function isQueuePaused(queueMetaKey)
160
- return rcall("HEXISTS", queueMetaKey, "paused") == 1
162
+ local function isQueuePausedOrMaxed(queueMetaKey, activeKey)
163
+ local queueAttributes = rcall("HMGET", queueMetaKey, "paused", "concurrency")
164
+ if queueAttributes[1] then
165
+ return true
166
+ else
167
+ if queueAttributes[2] then
168
+ local activeCount = rcall("LLEN", activeKey)
169
+ return activeCount >= tonumber(queueAttributes[2])
170
+ end
171
+ end
172
+ return false
161
173
  end
162
174
  --[[
163
175
  Function to check for the meta.paused key to decide if we are paused or not
164
176
  (since an empty list and !EXISTS are not really the same).
165
177
  ]]
166
- local function getTargetQueueList(queueMetaKey, waitKey, pausedKey)
167
- if rcall("HEXISTS", queueMetaKey, "paused") ~= 1 then
168
- return waitKey, false
169
- else
178
+ local function getTargetQueueList(queueMetaKey, activeKey, waitKey, pausedKey)
179
+ local queueAttributes = rcall("HMGET", queueMetaKey, "paused", "concurrency")
180
+ if queueAttributes[1] then
170
181
  return pausedKey, true
182
+ else
183
+ if queueAttributes[2] then
184
+ local activeCount = rcall("LLEN", activeKey)
185
+ if activeCount >= tonumber(queueAttributes[2]) then
186
+ return waitKey, true
187
+ else
188
+ return waitKey, false
189
+ end
190
+ end
171
191
  end
192
+ return waitKey, false
172
193
  end
173
194
  local function moveParentToWaitIfNeeded(parentQueueKey, parentDependenciesKey,
174
195
  parentKey, parentId, timestamp)
@@ -178,6 +199,7 @@ local function moveParentToWaitIfNeeded(parentQueueKey, parentDependenciesKey,
178
199
  rcall("ZREM", parentQueueKey .. ":waiting-children", parentId)
179
200
  local parentWaitKey = parentQueueKey .. ":wait"
180
201
  local parentPausedKey = parentQueueKey .. ":paused"
202
+ local parentActiveKey = parentQueueKey .. ":active"
181
203
  local parentMetaKey = parentQueueKey .. ":meta"
182
204
  local parentMarkerKey = parentQueueKey .. ":marker"
183
205
  local jobAttributes = rcall("HMGET", parentKey, "priority", "delay")
@@ -193,15 +215,16 @@ local function moveParentToWaitIfNeeded(parentQueueKey, parentDependenciesKey,
193
215
  addDelayMarkerIfNeeded(parentMarkerKey, parentDelayedKey)
194
216
  else
195
217
  if priority == 0 then
196
- local parentTarget, isParentPaused =
197
- getTargetQueueList(parentMetaKey, parentWaitKey,
218
+ local parentTarget, isParentPausedOrMaxed =
219
+ getTargetQueueList(parentMetaKey, parentActiveKey, parentWaitKey,
198
220
  parentPausedKey)
199
- addJobInTargetList(parentTarget, parentMarkerKey, "RPUSH", isParentPaused, parentId)
221
+ addJobInTargetList(parentTarget, parentMarkerKey, "RPUSH", isParentPausedOrMaxed,
222
+ parentId)
200
223
  else
201
- local isPaused = isQueuePaused(parentMetaKey)
224
+ local isPausedOrMaxed = isQueuePausedOrMaxed(parentMetaKey, parentActiveKey)
202
225
  addJobWithPriority(parentMarkerKey,
203
226
  parentQueueKey .. ":prioritized", priority,
204
- parentId, parentQueueKey .. ":pc", isPaused)
227
+ parentId, parentQueueKey .. ":pc", isPausedOrMaxed)
205
228
  end
206
229
  rcall("XADD", parentQueueKey .. ":events", "*", "event", "waiting",
207
230
  "jobId", parentId, "prev", "waiting-children")
@@ -273,8 +296,8 @@ local delay, priority = storeJob(eventsKey, jobIdKey, jobId, args[3], ARGV[2],
273
296
  opts, timestamp, parentKey, parentData,
274
297
  repeatJobKey)
275
298
  -- Add the job to the prioritized set
276
- local isPause = isQueuePaused(metaKey)
277
- addJobWithPriority( KEYS[1], priorityKey, priority, jobId, priorityCounterKey, isPause)
299
+ local isPausedOrMaxed = isQueuePausedOrMaxed(metaKey, activeKey)
300
+ addJobWithPriority( KEYS[1], priorityKey, priority, jobId, priorityCounterKey, isPausedOrMaxed)
278
301
  -- Emit waiting event
279
302
  rcall("XADD", eventsKey, "MAXLEN", "~", maxEvents, "*", "event", "waiting",
280
303
  "jobId", jobId)
@@ -287,6 +310,6 @@ return jobId .. "" -- convert to string
287
310
  exports.addPrioritizedJob = {
288
311
  name: 'addPrioritizedJob',
289
312
  content,
290
- keys: 7,
313
+ keys: 8,
291
314
  };
292
- //# sourceMappingURL=addPrioritizedJob-7.js.map
315
+ //# 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;AACW,QAAA,iBAAiB,GAAG;IAC/B,IAAI,EAAE,mBAAmB;IACzB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
@@ -21,8 +21,9 @@ const content = `--[[
21
21
  KEYS[3] 'meta'
22
22
  KEYS[4] 'id'
23
23
  KEYS[5] 'completed'
24
- KEYS[6] events stream key
25
- KEYS[7] marker key
24
+ KEYS[6] 'active'
25
+ KEYS[7] events stream key
26
+ KEYS[8] marker key
26
27
  ARGV[1] msgpacked arguments array
27
28
  [1] key prefix,
28
29
  [2] custom id (will not generate one automatically)
@@ -39,7 +40,7 @@ const content = `--[[
39
40
  jobId - OK
40
41
  -5 - Missing parent key
41
42
  ]]
42
- local eventsKey = KEYS[6]
43
+ local eventsKey = KEYS[7]
43
44
  local jobId
44
45
  local jobIdKey
45
46
  local rcall = redis.call
@@ -58,14 +59,14 @@ local parentData
58
59
  --[[
59
60
  Add marker if needed when a job is available.
60
61
  ]]
61
- local function addBaseMarkerIfNeeded(markerKey, isPaused)
62
- if not isPaused then
62
+ local function addBaseMarkerIfNeeded(markerKey, isPausedOrMaxed)
63
+ if not isPausedOrMaxed then
63
64
  rcall("ZADD", markerKey, 0, "0")
64
65
  end
65
66
  end
66
- local function addJobInTargetList(targetKey, markerKey, pushCmd, isPaused, jobId)
67
+ local function addJobInTargetList(targetKey, markerKey, pushCmd, isPausedOrMaxed, jobId)
67
68
  rcall(pushCmd, targetKey, jobId)
68
- addBaseMarkerIfNeeded(markerKey, isPaused)
69
+ addBaseMarkerIfNeeded(markerKey, isPausedOrMaxed)
69
70
  end
70
71
  --[[
71
72
  Function to get max events value or set by default 10000.
@@ -82,12 +83,21 @@ end
82
83
  Function to check for the meta.paused key to decide if we are paused or not
83
84
  (since an empty list and !EXISTS are not really the same).
84
85
  ]]
85
- local function getTargetQueueList(queueMetaKey, waitKey, pausedKey)
86
- if rcall("HEXISTS", queueMetaKey, "paused") ~= 1 then
87
- return waitKey, false
88
- else
86
+ local function getTargetQueueList(queueMetaKey, activeKey, waitKey, pausedKey)
87
+ local queueAttributes = rcall("HMGET", queueMetaKey, "paused", "concurrency")
88
+ if queueAttributes[1] then
89
89
  return pausedKey, true
90
+ else
91
+ if queueAttributes[2] then
92
+ local activeCount = rcall("LLEN", activeKey)
93
+ if activeCount >= tonumber(queueAttributes[2]) then
94
+ return waitKey, true
95
+ else
96
+ return waitKey, false
97
+ end
98
+ end
90
99
  end
100
+ return waitKey, false
91
101
  end
92
102
  --[[
93
103
  Function to handle the case when job is duplicated.
@@ -136,18 +146,28 @@ end
136
146
  Function to add job considering priority.
137
147
  ]]
138
148
  -- Includes
139
- local function addJobWithPriority(markerKey, prioritizedKey, priority, jobId, priorityCounterKey, isPaused)
149
+ local function addJobWithPriority(markerKey, prioritizedKey, priority, jobId, priorityCounterKey,
150
+ isPausedOrMaxed)
140
151
  local prioCounter = rcall("INCR", priorityCounterKey)
141
152
  local score = priority * 0x100000000 + prioCounter % 0x100000000
142
153
  rcall("ZADD", prioritizedKey, score, jobId)
143
- addBaseMarkerIfNeeded(markerKey, isPaused)
154
+ addBaseMarkerIfNeeded(markerKey, isPausedOrMaxed)
144
155
  end
145
156
  --[[
146
- Function to check for the meta.paused key to decide if we are paused or not
157
+ Function to check if queue is paused or maxed
147
158
  (since an empty list and !EXISTS are not really the same).
148
159
  ]]
149
- local function isQueuePaused(queueMetaKey)
150
- return rcall("HEXISTS", queueMetaKey, "paused") == 1
160
+ local function isQueuePausedOrMaxed(queueMetaKey, activeKey)
161
+ local queueAttributes = rcall("HMGET", queueMetaKey, "paused", "concurrency")
162
+ if queueAttributes[1] then
163
+ return true
164
+ else
165
+ if queueAttributes[2] then
166
+ local activeCount = rcall("LLEN", activeKey)
167
+ return activeCount >= tonumber(queueAttributes[2])
168
+ end
169
+ end
170
+ return false
151
171
  end
152
172
  local function moveParentToWaitIfNeeded(parentQueueKey, parentDependenciesKey,
153
173
  parentKey, parentId, timestamp)
@@ -157,6 +177,7 @@ local function moveParentToWaitIfNeeded(parentQueueKey, parentDependenciesKey,
157
177
  rcall("ZREM", parentQueueKey .. ":waiting-children", parentId)
158
178
  local parentWaitKey = parentQueueKey .. ":wait"
159
179
  local parentPausedKey = parentQueueKey .. ":paused"
180
+ local parentActiveKey = parentQueueKey .. ":active"
160
181
  local parentMetaKey = parentQueueKey .. ":meta"
161
182
  local parentMarkerKey = parentQueueKey .. ":marker"
162
183
  local jobAttributes = rcall("HMGET", parentKey, "priority", "delay")
@@ -172,15 +193,16 @@ local function moveParentToWaitIfNeeded(parentQueueKey, parentDependenciesKey,
172
193
  addDelayMarkerIfNeeded(parentMarkerKey, parentDelayedKey)
173
194
  else
174
195
  if priority == 0 then
175
- local parentTarget, isParentPaused =
176
- getTargetQueueList(parentMetaKey, parentWaitKey,
196
+ local parentTarget, isParentPausedOrMaxed =
197
+ getTargetQueueList(parentMetaKey, parentActiveKey, parentWaitKey,
177
198
  parentPausedKey)
178
- addJobInTargetList(parentTarget, parentMarkerKey, "RPUSH", isParentPaused, parentId)
199
+ addJobInTargetList(parentTarget, parentMarkerKey, "RPUSH", isParentPausedOrMaxed,
200
+ parentId)
179
201
  else
180
- local isPaused = isQueuePaused(parentMetaKey)
202
+ local isPausedOrMaxed = isQueuePausedOrMaxed(parentMetaKey, parentActiveKey)
181
203
  addJobWithPriority(parentMarkerKey,
182
204
  parentQueueKey .. ":prioritized", priority,
183
- parentId, parentQueueKey .. ":pc", isPaused)
205
+ parentId, parentQueueKey .. ":pc", isPausedOrMaxed)
184
206
  end
185
207
  rcall("XADD", parentQueueKey .. ":events", "*", "event", "waiting",
186
208
  "jobId", parentId, "prev", "waiting-children")
@@ -276,10 +298,10 @@ end
276
298
  -- Store the job.
277
299
  storeJob(eventsKey, jobIdKey, jobId, args[3], ARGV[2], opts, timestamp,
278
300
  parentKey, parentData, repeatJobKey)
279
- local target, paused = getTargetQueueList(metaKey, KEYS[1], KEYS[2])
301
+ local target, isPausedOrMaxed = getTargetQueueList(metaKey, KEYS[6], KEYS[1], KEYS[2])
280
302
  -- LIFO or FIFO
281
303
  local pushCmd = opts['lifo'] and 'RPUSH' or 'LPUSH'
282
- addJobInTargetList(target, KEYS[7], pushCmd, paused, jobId)
304
+ addJobInTargetList(target, KEYS[8], pushCmd, isPausedOrMaxed, jobId)
283
305
  -- Emit waiting event
284
306
  rcall("XADD", eventsKey, "MAXLEN", "~", maxEvents, "*", "event", "waiting",
285
307
  "jobId", jobId)
@@ -292,6 +314,6 @@ return jobId .. "" -- convert to string
292
314
  exports.addStandardJob = {
293
315
  name: 'addStandardJob',
294
316
  content,
295
- keys: 7,
317
+ keys: 8,
296
318
  };
297
- //# sourceMappingURL=addStandardJob-7.js.map
319
+ //# 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;AACW,QAAA,cAAc,GAAG;IAC5B,IAAI,EAAE,gBAAgB;IACtB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
@@ -80,13 +80,6 @@ local function getOrSetMaxEvents(metaKey)
80
80
  end
81
81
  return maxEvents
82
82
  end
83
- --[[
84
- Function to check for the meta.paused key to decide if we are paused or not
85
- (since an empty list and !EXISTS are not really the same).
86
- ]]
87
- local function isQueuePaused(queueMetaKey)
88
- return rcall("HEXISTS", queueMetaKey, "paused") == 1
89
- end
90
83
  if rcall("EXISTS", ARGV[4]) == 1 then
91
84
  local jobId = ARGV[3]
92
85
  local delay = tonumber(ARGV[1])
@@ -101,10 +94,7 @@ if rcall("EXISTS", ARGV[4]) == 1 then
101
94
  rcall("XADD", KEYS[4], "MAXLEN", "~", maxEvents, "*", "event", "delayed",
102
95
  "jobId", jobId, "delay", delayedTimestamp)
103
96
  -- mark that a delayed job is available
104
- local isPaused = isQueuePaused(KEYS[2])
105
- if not isPaused then
106
- addDelayMarkerIfNeeded(KEYS[3], KEYS[1])
107
- end
97
+ addDelayMarkerIfNeeded(KEYS[3], KEYS[1])
108
98
  return 0
109
99
  else
110
100
  return -1
@@ -1 +1 @@
1
- {"version":3,"file":"changeDelay-4.js","sourceRoot":"","sources":["../../../src/scripts/changeDelay-4.ts"],"names":[],"mappings":";;;AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IA2GZ,CAAC;AACQ,QAAA,WAAW,GAAG;IACzB,IAAI,EAAE,aAAa;IACnB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
1
+ {"version":3,"file":"changeDelay-4.js","sourceRoot":"","sources":["../../../src/scripts/changeDelay-4.ts"],"names":[],"mappings":";;;AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAiGZ,CAAC;AACQ,QAAA,WAAW,GAAG;IACzB,IAAI,EAAE,aAAa;IACnB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
@@ -8,8 +8,9 @@ const content = `--[[
8
8
  KEYS[2] 'paused'
9
9
  KEYS[3] 'meta'
10
10
  KEYS[4] 'prioritized'
11
- KEYS[5] 'pc' priority counter
12
- KEYS[6] 'marker'
11
+ KEYS[5] 'active'
12
+ KEYS[6] 'pc' priority counter
13
+ KEYS[7] 'marker'
13
14
  ARGV[1] priority value
14
15
  ARGV[2] job key
15
16
  ARGV[3] job id
@@ -30,35 +31,45 @@ local rcall = redis.call
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
  --[[
64
75
  Function to push back job considering priority in front of same prioritized jobs.
@@ -70,31 +81,32 @@ local function pushBackJobWithPriority(prioritizedKey, priority, jobId)
70
81
  rcall("ZADD", prioritizedKey, score, jobId)
71
82
  end
72
83
  local function reAddJobWithNewPriority( prioritizedKey, markerKey, targetKey,
73
- priorityCounter, lifo, priority, jobId, paused)
84
+ priorityCounter, lifo, priority, jobId, isPausedOrMaxed)
74
85
  if priority == 0 then
75
86
  local pushCmd = lifo and 'RPUSH' or 'LPUSH'
76
- addJobInTargetList(targetKey, markerKey, pushCmd, paused, jobId)
87
+ addJobInTargetList(targetKey, markerKey, pushCmd, isPausedOrMaxed, jobId)
77
88
  else
78
89
  if lifo then
79
90
  pushBackJobWithPriority(prioritizedKey, priority, jobId)
80
91
  else
81
92
  addJobWithPriority(markerKey, prioritizedKey, priority, jobId,
82
- priorityCounter, paused)
93
+ priorityCounter, isPausedOrMaxed)
83
94
  end
84
95
  end
85
96
  end
86
97
  if rcall("EXISTS", jobKey) == 1 then
87
98
  local metaKey = KEYS[3]
88
- local target, isPaused = getTargetQueueList(metaKey, KEYS[1], KEYS[2])
89
- local markerKey = KEYS[6]
99
+ local target, isPausedOrMaxed = getTargetQueueList(metaKey, KEYS[5], KEYS[1], KEYS[2])
90
100
  local prioritizedKey = KEYS[4]
101
+ local priorityCounterKey = KEYS[6]
102
+ local markerKey = KEYS[7]
91
103
  -- Re-add with the new priority
92
104
  if rcall("ZREM", KEYS[4], jobId) > 0 then
93
105
  reAddJobWithNewPriority( prioritizedKey, markerKey, target,
94
- KEYS[5], ARGV[4] == '1', priority, jobId, isPaused)
106
+ priorityCounterKey, ARGV[4] == '1', priority, jobId, isPausedOrMaxed)
95
107
  elseif rcall("LREM", target, -1, jobId) > 0 then
96
108
  reAddJobWithNewPriority( prioritizedKey, markerKey, target,
97
- KEYS[5], ARGV[4] == '1', priority, jobId, isPaused)
109
+ priorityCounterKey, ARGV[4] == '1', priority, jobId, isPausedOrMaxed)
98
110
  end
99
111
  rcall("HSET", jobKey, "priority", priority)
100
112
  return 0
@@ -105,6 +117,6 @@ end
105
117
  exports.changePriority = {
106
118
  name: 'changePriority',
107
119
  content,
108
- keys: 6,
120
+ keys: 7,
109
121
  };
110
- //# sourceMappingURL=changePriority-6.js.map
122
+ //# sourceMappingURL=changePriority-7.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"changePriority-7.js","sourceRoot":"","sources":["../../../src/scripts/changePriority-7.ts"],"names":[],"mappings":";;;AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgHf,CAAC;AACW,QAAA,cAAc,GAAG;IAC5B,IAAI,EAAE,gBAAgB;IACtB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
@@ -70,14 +70,14 @@ end
70
70
  --[[
71
71
  Add marker if needed when a job is available.
72
72
  ]]
73
- local function addBaseMarkerIfNeeded(markerKey, isPaused)
74
- if not isPaused then
73
+ local function addBaseMarkerIfNeeded(markerKey, isPausedOrMaxed)
74
+ if not isPausedOrMaxed then
75
75
  rcall("ZADD", markerKey, 0, "0")
76
76
  end
77
77
  end
78
- local function addJobInTargetList(targetKey, markerKey, pushCmd, isPaused, jobId)
78
+ local function addJobInTargetList(targetKey, markerKey, pushCmd, isPausedOrMaxed, jobId)
79
79
  rcall(pushCmd, targetKey, jobId)
80
- addBaseMarkerIfNeeded(markerKey, isPaused)
80
+ addBaseMarkerIfNeeded(markerKey, isPausedOrMaxed)
81
81
  end
82
82
  --[[
83
83
  Functions to destructure job key.
@@ -93,17 +93,26 @@ end
93
93
  Function to check for the meta.paused key to decide if we are paused or not
94
94
  (since an empty list and !EXISTS are not really the same).
95
95
  ]]
96
- local function getTargetQueueList(queueMetaKey, waitKey, pausedKey)
97
- if rcall("HEXISTS", queueMetaKey, "paused") ~= 1 then
98
- return waitKey, false
99
- else
96
+ local function getTargetQueueList(queueMetaKey, activeKey, waitKey, pausedKey)
97
+ local queueAttributes = rcall("HMGET", queueMetaKey, "paused", "concurrency")
98
+ if queueAttributes[1] then
100
99
  return pausedKey, true
100
+ else
101
+ if queueAttributes[2] then
102
+ local activeCount = rcall("LLEN", activeKey)
103
+ if activeCount >= tonumber(queueAttributes[2]) then
104
+ return waitKey, true
105
+ else
106
+ return waitKey, false
107
+ end
108
+ end
101
109
  end
110
+ return waitKey, false
102
111
  end
103
112
  local function moveParentToWait(parentPrefix, parentId, emitEvent)
104
- local parentTarget, isPaused = getTargetQueueList(parentPrefix .. "meta", parentPrefix .. "wait",
105
- parentPrefix .. "paused")
106
- addJobInTargetList(parentTarget, parentPrefix .. "marker", "RPUSH", isPaused, parentId)
113
+ local parentTarget, isPausedOrMaxed = getTargetQueueList(parentPrefix .. "meta", parentPrefix .. "active",
114
+ parentPrefix .. "wait", parentPrefix .. "paused")
115
+ addJobInTargetList(parentTarget, parentPrefix .. "marker", "RPUSH", isPausedOrMaxed, parentId)
107
116
  if emitEvent then
108
117
  local parentEventStream = parentPrefix .. "events"
109
118
  rcall("XADD", parentEventStream, "*", "event", "waiting", "jobId", parentId, "prev", "waiting-children")
@@ -1 +1 @@
1
- {"version":3,"file":"cleanJobsInSet-2.js","sourceRoot":"","sources":["../../../src/scripts/cleanJobsInSet-2.ts"],"names":[],"mappings":";;;AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiSf,CAAC;AACW,QAAA,cAAc,GAAG;IAC5B,IAAI,EAAE,gBAAgB;IACtB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
1
+ {"version":3,"file":"cleanJobsInSet-2.js","sourceRoot":"","sources":["../../../src/scripts/cleanJobsInSet-2.ts"],"names":[],"mappings":";;;AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA0Sf,CAAC;AACW,QAAA,cAAc,GAAG;IAC5B,IAAI,EAAE,gBAAgB;IACtB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}