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