bullmq 5.1.3 → 5.1.4

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 (99) hide show
  1. package/dist/cjs/classes/scripts.js +1 -0
  2. package/dist/cjs/classes/scripts.js.map +1 -1
  3. package/dist/cjs/commands/addStandardJob-7.lua +4 -8
  4. package/dist/cjs/commands/changeDelay-3.lua +1 -0
  5. package/dist/cjs/commands/changePriority-6.lua +0 -1
  6. package/dist/cjs/commands/includes/addBaseMarkerIfNeeded.lua +9 -0
  7. package/dist/cjs/commands/includes/addDelayMarkerIfNeeded.lua +3 -1
  8. package/dist/cjs/commands/includes/addJobInTargetList.lua +11 -0
  9. package/dist/cjs/commands/includes/addJobWithPriority.lua +5 -3
  10. package/dist/cjs/commands/includes/moveParentToWaitIfNeeded.lua +6 -4
  11. package/dist/cjs/commands/includes/promoteDelayedJobs.lua +2 -4
  12. package/dist/cjs/commands/moveJobsToWait-7.lua +2 -3
  13. package/dist/cjs/commands/moveStalledJobsToWait-9.lua +150 -0
  14. package/dist/cjs/commands/moveToFinished-14.lua +1 -0
  15. package/dist/cjs/commands/pause-7.lua +1 -0
  16. package/dist/cjs/commands/promote-8.lua +2 -2
  17. package/dist/cjs/commands/retryJob-10.lua +1 -0
  18. package/dist/cjs/scripts/addDelayedJob-6.js +21 -7
  19. package/dist/cjs/scripts/addDelayedJob-6.js.map +1 -1
  20. package/dist/cjs/scripts/addParentJob-4.js +25 -11
  21. package/dist/cjs/scripts/addParentJob-4.js.map +1 -1
  22. package/dist/cjs/scripts/addPrioritizedJob-7.js +21 -7
  23. package/dist/cjs/scripts/addPrioritizedJob-7.js.map +1 -1
  24. package/dist/cjs/scripts/addStandardJob-7.js +46 -36
  25. package/dist/cjs/scripts/addStandardJob-7.js.map +1 -1
  26. package/dist/cjs/scripts/changeDelay-3.js +1 -0
  27. package/dist/cjs/scripts/changeDelay-3.js.map +1 -1
  28. package/dist/cjs/scripts/changePriority-6.js +10 -14
  29. package/dist/cjs/scripts/changePriority-6.js.map +1 -1
  30. package/dist/cjs/scripts/index.js +1 -1
  31. package/dist/cjs/scripts/moveJobsToWait-7.js +9 -3
  32. package/dist/cjs/scripts/moveJobsToWait-7.js.map +1 -1
  33. package/dist/cjs/scripts/{moveStalledJobsToWait-8.js → moveStalledJobsToWait-9.js} +109 -106
  34. package/dist/cjs/scripts/{moveStalledJobsToWait-8.js.map → moveStalledJobsToWait-9.js.map} +1 -1
  35. package/dist/cjs/scripts/moveToActive-11.js +19 -7
  36. package/dist/cjs/scripts/moveToActive-11.js.map +1 -1
  37. package/dist/cjs/scripts/moveToDelayed-7.js +1 -1
  38. package/dist/cjs/scripts/moveToFinished-14.js +32 -21
  39. package/dist/cjs/scripts/moveToFinished-14.js.map +1 -1
  40. package/dist/cjs/scripts/pause-7.js +2 -1
  41. package/dist/cjs/scripts/pause-7.js.map +1 -1
  42. package/dist/cjs/scripts/promote-8.js +19 -5
  43. package/dist/cjs/scripts/promote-8.js.map +1 -1
  44. package/dist/cjs/scripts/retryJob-10.js +20 -7
  45. package/dist/cjs/scripts/retryJob-10.js.map +1 -1
  46. package/dist/cjs/tsconfig-cjs.tsbuildinfo +1 -1
  47. package/dist/esm/classes/scripts.js +1 -0
  48. package/dist/esm/classes/scripts.js.map +1 -1
  49. package/dist/esm/commands/addStandardJob-7.lua +4 -8
  50. package/dist/esm/commands/changeDelay-3.lua +1 -0
  51. package/dist/esm/commands/changePriority-6.lua +0 -1
  52. package/dist/esm/commands/includes/addBaseMarkerIfNeeded.lua +9 -0
  53. package/dist/esm/commands/includes/addDelayMarkerIfNeeded.lua +3 -1
  54. package/dist/esm/commands/includes/addJobInTargetList.lua +11 -0
  55. package/dist/esm/commands/includes/addJobWithPriority.lua +5 -3
  56. package/dist/esm/commands/includes/moveParentToWaitIfNeeded.lua +6 -4
  57. package/dist/esm/commands/includes/promoteDelayedJobs.lua +2 -4
  58. package/dist/esm/commands/moveJobsToWait-7.lua +2 -3
  59. package/dist/esm/commands/moveStalledJobsToWait-9.lua +150 -0
  60. package/dist/esm/commands/moveToFinished-14.lua +1 -0
  61. package/dist/esm/commands/pause-7.lua +1 -0
  62. package/dist/esm/commands/promote-8.lua +2 -2
  63. package/dist/esm/commands/retryJob-10.lua +1 -0
  64. package/dist/esm/scripts/addDelayedJob-6.js +21 -7
  65. package/dist/esm/scripts/addDelayedJob-6.js.map +1 -1
  66. package/dist/esm/scripts/addParentJob-4.js +25 -11
  67. package/dist/esm/scripts/addParentJob-4.js.map +1 -1
  68. package/dist/esm/scripts/addPrioritizedJob-7.js +21 -7
  69. package/dist/esm/scripts/addPrioritizedJob-7.js.map +1 -1
  70. package/dist/esm/scripts/addStandardJob-7.js +46 -36
  71. package/dist/esm/scripts/addStandardJob-7.js.map +1 -1
  72. package/dist/esm/scripts/changeDelay-3.js +1 -0
  73. package/dist/esm/scripts/changeDelay-3.js.map +1 -1
  74. package/dist/esm/scripts/changePriority-6.js +10 -14
  75. package/dist/esm/scripts/changePriority-6.js.map +1 -1
  76. package/dist/esm/scripts/index.d.ts +1 -1
  77. package/dist/esm/scripts/index.js +1 -1
  78. package/dist/esm/scripts/moveJobsToWait-7.js +9 -3
  79. package/dist/esm/scripts/moveJobsToWait-7.js.map +1 -1
  80. package/dist/esm/scripts/{moveStalledJobsToWait-8.js → moveStalledJobsToWait-9.js} +109 -106
  81. package/dist/esm/scripts/{moveStalledJobsToWait-8.js.map → moveStalledJobsToWait-9.js.map} +1 -1
  82. package/dist/esm/scripts/moveToActive-11.js +19 -7
  83. package/dist/esm/scripts/moveToActive-11.js.map +1 -1
  84. package/dist/esm/scripts/moveToDelayed-7.js +1 -1
  85. package/dist/esm/scripts/moveToFinished-14.js +32 -21
  86. package/dist/esm/scripts/moveToFinished-14.js.map +1 -1
  87. package/dist/esm/scripts/pause-7.js +2 -1
  88. package/dist/esm/scripts/pause-7.js.map +1 -1
  89. package/dist/esm/scripts/promote-8.js +19 -5
  90. package/dist/esm/scripts/promote-8.js.map +1 -1
  91. package/dist/esm/scripts/retryJob-10.js +20 -7
  92. package/dist/esm/scripts/retryJob-10.js.map +1 -1
  93. package/dist/esm/tsconfig.tsbuildinfo +1 -1
  94. package/package.json +1 -1
  95. package/dist/cjs/commands/includes/checkStalledJobs.lua +0 -139
  96. package/dist/cjs/commands/moveStalledJobsToWait-8.lua +0 -24
  97. package/dist/esm/commands/includes/checkStalledJobs.lua +0 -139
  98. package/dist/esm/commands/moveStalledJobsToWait-8.lua +0 -24
  99. /package/dist/esm/scripts/{moveStalledJobsToWait-8.d.ts → moveStalledJobsToWait-9.d.ts} +0 -0
@@ -82,13 +82,20 @@ end
82
82
  --[[
83
83
  Function to add job considering priority.
84
84
  ]]
85
+ -- Includes
86
+ --[[
87
+ Add marker if needed when a job is available.
88
+ ]]
89
+ local function addBaseMarkerIfNeeded(markerKey, isPaused)
90
+ if not isPaused then
91
+ rcall("ZADD", markerKey, 0, "0")
92
+ end
93
+ end
85
94
  local function addJobWithPriority(markerKey, prioritizedKey, priority, jobId, priorityCounterKey, isPaused)
86
95
  local prioCounter = rcall("INCR", priorityCounterKey)
87
96
  local score = priority * 0x100000000 + bit.band(prioCounter, 0xffffffffffff)
88
97
  rcall("ZADD", prioritizedKey, score, jobId)
89
- if not isPaused then
90
- rcall("ZADD", markerKey, 0, "0")
91
- end
98
+ addBaseMarkerIfNeeded(markerKey, isPaused)
92
99
  end
93
100
  --[[
94
101
  This function is used to update the parent's dependencies if the job
@@ -107,7 +114,7 @@ end
107
114
  -- Includes
108
115
  --[[
109
116
  Add delay marker if needed.
110
- ]]
117
+ ]]
111
118
  -- Includes
112
119
  --[[
113
120
  Function to return the next delayed job timestamp.
@@ -130,6 +137,14 @@ local function addDelayMarkerIfNeeded(markerKey, delayedKey)
130
137
  rcall("ZADD", markerKey, nextTimestamp, "0")
131
138
  end
132
139
  end
140
+ --[[
141
+ Function to add job in target list and add marker if needed.
142
+ ]]
143
+ -- Includes
144
+ local function addJobInTargetList(targetKey, markerKey, pushCmd, isPaused, jobId)
145
+ rcall(pushCmd, targetKey, jobId)
146
+ addBaseMarkerIfNeeded(markerKey, isPaused)
147
+ end
133
148
  --[[
134
149
  Function to check for the meta.paused key to decide if we are paused or not
135
150
  (since an empty list and !EXISTS are not really the same).
@@ -164,11 +179,10 @@ local function moveParentToWaitIfNeeded(parentQueueKey, parentDependenciesKey,
164
179
  addDelayMarkerIfNeeded(parentMarkerKey, parentDelayedKey)
165
180
  else
166
181
  if priority == 0 then
167
- local parentTarget, _paused =
182
+ local parentTarget, isParentPaused =
168
183
  getTargetQueueList(parentMetaKey, parentWaitKey,
169
184
  parentPausedKey)
170
- rcall("RPUSH", parentTarget, parentId)
171
- rcall("ZADD", parentMarkerKey, 0, "0")
185
+ addJobInTargetList(parentTarget, parentMarkerKey, "RPUSH", isParentPaused, parentId)
172
186
  else
173
187
  local isPaused = isQueuePaused(parentMetaKey)
174
188
  addJobWithPriority(parentMarkerKey,
@@ -1 +1 @@
1
- {"version":3,"file":"addPrioritizedJob-7.js","sourceRoot":"","sources":["../../../src/scripts/addPrioritizedJob-7.ts"],"names":[],"mappings":";;;AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2Pf,CAAC;AACW,QAAA,iBAAiB,GAAG;IAC/B,IAAI,EAAE,mBAAmB;IACzB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
1
+ {"version":3,"file":"addPrioritizedJob-7.js","sourceRoot":"","sources":["../../../src/scripts/addPrioritizedJob-7.ts"],"names":[],"mappings":";;;AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyQf,CAAC;AACW,QAAA,iBAAiB,GAAG;IAC/B,IAAI,EAAE,mBAAmB;IACzB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
@@ -51,6 +51,44 @@ local repeatJobKey = args[9]
51
51
  local parent = args[8]
52
52
  local parentData
53
53
  -- Includes
54
+ --[[
55
+ Function to add job in target list and add marker if needed.
56
+ ]]
57
+ -- Includes
58
+ --[[
59
+ Add marker if needed when a job is available.
60
+ ]]
61
+ local function addBaseMarkerIfNeeded(markerKey, isPaused)
62
+ if not isPaused then
63
+ rcall("ZADD", markerKey, 0, "0")
64
+ end
65
+ end
66
+ local function addJobInTargetList(targetKey, markerKey, pushCmd, isPaused, jobId)
67
+ rcall(pushCmd, targetKey, jobId)
68
+ addBaseMarkerIfNeeded(markerKey, isPaused)
69
+ end
70
+ --[[
71
+ Function to get max events value or set by default 10000.
72
+ ]]
73
+ local function getOrSetMaxEvents(metaKey)
74
+ local maxEvents = rcall("HGET", metaKey, "opts.maxLenEvents")
75
+ if not maxEvents then
76
+ maxEvents = 10000
77
+ rcall("HSET", metaKey, "opts.maxLenEvents", maxEvents)
78
+ end
79
+ return maxEvents
80
+ end
81
+ --[[
82
+ Function to check for the meta.paused key to decide if we are paused or not
83
+ (since an empty list and !EXISTS are not really the same).
84
+ ]]
85
+ local function getTargetQueueList(queueMetaKey, waitKey, pausedKey)
86
+ if rcall("HEXISTS", queueMetaKey, "paused") ~= 1 then
87
+ return waitKey, false
88
+ else
89
+ return pausedKey, true
90
+ end
91
+ end
54
92
  --[[
55
93
  Function to store a job
56
94
  ]]
@@ -93,7 +131,7 @@ end
93
131
  -- Includes
94
132
  --[[
95
133
  Add delay marker if needed.
96
- ]]
134
+ ]]
97
135
  -- Includes
98
136
  --[[
99
137
  Function to return the next delayed job timestamp.
@@ -116,34 +154,22 @@ local function addDelayMarkerIfNeeded(markerKey, delayedKey)
116
154
  rcall("ZADD", markerKey, nextTimestamp, "0")
117
155
  end
118
156
  end
119
- --[[
120
- Function to check for the meta.paused key to decide if we are paused or not
121
- (since an empty list and !EXISTS are not really the same).
122
- ]]
123
- local function isQueuePaused(queueMetaKey)
124
- return rcall("HEXISTS", queueMetaKey, "paused") == 1
125
- end
126
157
  --[[
127
158
  Function to add job considering priority.
128
159
  ]]
160
+ -- Includes
129
161
  local function addJobWithPriority(markerKey, prioritizedKey, priority, jobId, priorityCounterKey, isPaused)
130
162
  local prioCounter = rcall("INCR", priorityCounterKey)
131
163
  local score = priority * 0x100000000 + bit.band(prioCounter, 0xffffffffffff)
132
164
  rcall("ZADD", prioritizedKey, score, jobId)
133
- if not isPaused then
134
- rcall("ZADD", markerKey, 0, "0")
135
- end
165
+ addBaseMarkerIfNeeded(markerKey, isPaused)
136
166
  end
137
167
  --[[
138
168
  Function to check for the meta.paused key to decide if we are paused or not
139
169
  (since an empty list and !EXISTS are not really the same).
140
170
  ]]
141
- local function getTargetQueueList(queueMetaKey, waitKey, pausedKey)
142
- if rcall("HEXISTS", queueMetaKey, "paused") ~= 1 then
143
- return waitKey, false
144
- else
145
- return pausedKey, true
146
- end
171
+ local function isQueuePaused(queueMetaKey)
172
+ return rcall("HEXISTS", queueMetaKey, "paused") == 1
147
173
  end
148
174
  local function moveParentToWaitIfNeeded(parentQueueKey, parentDependenciesKey,
149
175
  parentKey, parentId, timestamp)
@@ -168,11 +194,10 @@ local function moveParentToWaitIfNeeded(parentQueueKey, parentDependenciesKey,
168
194
  addDelayMarkerIfNeeded(parentMarkerKey, parentDelayedKey)
169
195
  else
170
196
  if priority == 0 then
171
- local parentTarget, _paused =
197
+ local parentTarget, isParentPaused =
172
198
  getTargetQueueList(parentMetaKey, parentWaitKey,
173
199
  parentPausedKey)
174
- rcall("RPUSH", parentTarget, parentId)
175
- rcall("ZADD", parentMarkerKey, 0, "0")
200
+ addJobInTargetList(parentTarget, parentMarkerKey, "RPUSH", isParentPaused, parentId)
176
201
  else
177
202
  local isPaused = isQueuePaused(parentMetaKey)
178
203
  addJobWithPriority(parentMarkerKey,
@@ -207,17 +232,6 @@ local function updateExistingJobsParent(parentKey, parent, parentData,
207
232
  rcall("HMSET", jobIdKey, "parentKey", parentKey, "parent", parentData)
208
233
  end
209
234
  end
210
- --[[
211
- Function to get max events value or set by default 10000.
212
- ]]
213
- local function getOrSetMaxEvents(metaKey)
214
- local maxEvents = rcall("HGET", metaKey, "opts.maxLenEvents")
215
- if not maxEvents then
216
- maxEvents = 10000
217
- rcall("HSET", metaKey, "opts.maxLenEvents", maxEvents)
218
- end
219
- return maxEvents
220
- end
221
235
  if parentKey ~= nil then
222
236
  if rcall("EXISTS", parentKey) ~= 1 then return -5 end
223
237
  parentData = cjson.encode(parent)
@@ -246,13 +260,9 @@ end
246
260
  storeJob(eventsKey, jobIdKey, jobId, args[3], ARGV[2], opts, timestamp,
247
261
  parentKey, parentData, repeatJobKey)
248
262
  local target, paused = getTargetQueueList(metaKey, KEYS[1], KEYS[2])
249
- if not paused then
250
- -- mark that a job is available
251
- rcall("ZADD", KEYS[7], 0, "0")
252
- end
253
263
  -- LIFO or FIFO
254
264
  local pushCmd = opts['lifo'] and 'RPUSH' or 'LPUSH'
255
- rcall(pushCmd, target, jobId)
265
+ addJobInTargetList(target, KEYS[7], pushCmd, paused, jobId)
256
266
  -- Emit waiting event
257
267
  rcall("XADD", eventsKey, "MAXLEN", "~", maxEvents, "*", "event", "waiting",
258
268
  "jobId", jobId)
@@ -1 +1 @@
1
- {"version":3,"file":"addStandardJob-7.js","sourceRoot":"","sources":["../../../src/scripts/addStandardJob-7.ts"],"names":[],"mappings":";;;AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAoQf,CAAC;AACW,QAAA,cAAc,GAAG;IAC5B,IAAI,EAAE,gBAAgB;IACtB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
1
+ {"version":3,"file":"addStandardJob-7.js","sourceRoot":"","sources":["../../../src/scripts/addStandardJob-7.ts"],"names":[],"mappings":";;;AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8Qf,CAAC;AACW,QAAA,cAAc,GAAG;IAC5B,IAAI,EAAE,gBAAgB;IACtB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
@@ -28,6 +28,7 @@ if rcall("EXISTS", KEYS[2]) == 1 then
28
28
  end
29
29
  rcall("HSET", KEYS[2], "delay", tonumber(ARGV[1]))
30
30
  rcall("ZADD", KEYS[1], score, jobId)
31
+ -- TODO: check if we need to evaluate a new marker
31
32
  rcall("XADD", KEYS[3], "*", "event", "delayed", "jobId", jobId, "delay", delayedTimestamp)
32
33
  return 0
33
34
  else
@@ -1 +1 @@
1
- {"version":3,"file":"changeDelay-3.js","sourceRoot":"","sources":["../../../src/scripts/changeDelay-3.ts"],"names":[],"mappings":";;;AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IA+BZ,CAAC;AACQ,QAAA,WAAW,GAAG;IACzB,IAAI,EAAE,aAAa;IACnB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
1
+ {"version":3,"file":"changeDelay-3.js","sourceRoot":"","sources":["../../../src/scripts/changeDelay-3.ts"],"names":[],"mappings":";;;AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAgCZ,CAAC;AACQ,QAAA,WAAW,GAAG;IACzB,IAAI,EAAE,aAAa;IACnB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
@@ -33,24 +33,20 @@ end
33
33
  --[[
34
34
  Function to add job considering priority.
35
35
  ]]
36
+ -- Includes
37
+ --[[
38
+ Add marker if needed when a job is available.
39
+ ]]
40
+ local function addBaseMarkerIfNeeded(markerKey, isPaused)
41
+ if not isPaused then
42
+ rcall("ZADD", markerKey, 0, "0")
43
+ end
44
+ end
36
45
  local function addJobWithPriority(markerKey, prioritizedKey, priority, jobId, priorityCounterKey, isPaused)
37
46
  local prioCounter = rcall("INCR", priorityCounterKey)
38
47
  local score = priority * 0x100000000 + bit.band(prioCounter, 0xffffffffffff)
39
48
  rcall("ZADD", prioritizedKey, score, jobId)
40
- if not isPaused then
41
- rcall("ZADD", markerKey, 0, "0")
42
- end
43
- end
44
- --[[
45
- Function to check for the meta.paused key to decide if we are paused or not
46
- (since an empty list and !EXISTS are not really the same).
47
- ]]
48
- local function getTargetQueueList(queueMetaKey, waitKey, pausedKey)
49
- if rcall("HEXISTS", queueMetaKey, "paused") ~= 1 then
50
- return waitKey, false
51
- else
52
- return pausedKey, true
53
- end
49
+ addBaseMarkerIfNeeded(markerKey, isPaused)
54
50
  end
55
51
  if rcall("EXISTS", jobKey) == 1 then
56
52
  local metaKey = KEYS[3]
@@ -1 +1 @@
1
- {"version":3,"file":"changePriority-6.js","sourceRoot":"","sources":["../../../src/scripts/changePriority-6.ts"],"names":[],"mappings":";;;AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2Ef,CAAC;AACW,QAAA,cAAc,GAAG;IAC5B,IAAI,EAAE,gBAAgB;IACtB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
1
+ {"version":3,"file":"changePriority-6.js","sourceRoot":"","sources":["../../../src/scripts/changePriority-6.ts"],"names":[],"mappings":";;;AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAuEf,CAAC;AACW,QAAA,cAAc,GAAG;IAC5B,IAAI,EAAE,gBAAgB;IACtB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
@@ -18,7 +18,7 @@ tslib_1.__exportStar(require("./isFinished-3"), exports);
18
18
  tslib_1.__exportStar(require("./isJobInList-1"), exports);
19
19
  tslib_1.__exportStar(require("./moveJobFromActiveToWait-9"), exports);
20
20
  tslib_1.__exportStar(require("./moveJobsToWait-7"), exports);
21
- tslib_1.__exportStar(require("./moveStalledJobsToWait-8"), exports);
21
+ tslib_1.__exportStar(require("./moveStalledJobsToWait-9"), exports);
22
22
  tslib_1.__exportStar(require("./moveToActive-11"), exports);
23
23
  tslib_1.__exportStar(require("./moveToDelayed-7"), exports);
24
24
  tslib_1.__exportStar(require("./moveToFinished-14"), exports);
@@ -23,6 +23,14 @@ local maxCount = tonumber(ARGV[1])
23
23
  local timestamp = tonumber(ARGV[2])
24
24
  local rcall = redis.call;
25
25
  -- Includes
26
+ --[[
27
+ Add marker if needed when a job is available.
28
+ ]]
29
+ local function addBaseMarkerIfNeeded(markerKey, isPaused)
30
+ if not isPaused then
31
+ rcall("ZADD", markerKey, 0, "0")
32
+ end
33
+ end
26
34
  --[[
27
35
  Function to loop in batches.
28
36
  Just a bit of warning, some commands as ZREM
@@ -86,9 +94,7 @@ if (#jobs > 0) then
86
94
  rcall("ZREM", KEYS[3], unpack(jobs, from, to))
87
95
  rcall("LPUSH", target, unpack(jobs, from, to))
88
96
  end
89
- if not paused then
90
- rcall("ZADD", KEYS[7], 0, "0")
91
- end
97
+ addBaseMarkerIfNeeded(KEYS[7], paused)
92
98
  end
93
99
  maxCount = maxCount - #jobs
94
100
  if (maxCount <= 0) then return 1 end
@@ -1 +1 @@
1
- {"version":3,"file":"moveJobsToWait-7.js","sourceRoot":"","sources":["../../../src/scripts/moveJobsToWait-7.ts"],"names":[],"mappings":";;;AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4Ff,CAAC;AACW,QAAA,cAAc,GAAG;IAC5B,IAAI,EAAE,gBAAgB;IACtB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
1
+ {"version":3,"file":"moveJobsToWait-7.js","sourceRoot":"","sources":["../../../src/scripts/moveJobsToWait-7.ts"],"names":[],"mappings":";;;AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkGf,CAAC;AACW,QAAA,cAAc,GAAG;IAC5B,IAAI,EAAE,gBAAgB;IACtB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
@@ -11,34 +11,33 @@ const content = `--[[
11
11
  KEYS[5] 'stalled-check', (KEY)
12
12
  KEYS[6] 'meta', (KEY)
13
13
  KEYS[7] 'paused', (LIST)
14
- KEYS[8] 'event stream' (STREAM)
14
+ KEYS[8] 'marker'
15
+ KEYS[9] 'event stream' (STREAM)
15
16
  ARGV[1] Max stalled job count
16
17
  ARGV[2] queue.toKey('')
17
18
  ARGV[3] timestamp
18
19
  ARGV[4] max check time
19
20
  Events:
20
21
  'stalled' with stalled job id.
21
- ]] -- Includes
22
- --[[
23
- Move stalled jobs to wait.
24
- Input:
25
- stalledKey 'stalled' (SET)
26
- waitKey 'wait', (LIST)
27
- activeKey 'active', (LIST)
28
- failedKey 'failed', (ZSET)
29
- stalledCheckKey 'stalled-check', (KEY)
30
- metaKey 'meta', (KEY)
31
- pausedKey 'paused', (LIST)
32
- eventStreamKey 'event stream' (STREAM)
33
- maxStalledJobCount Max stalled job count
34
- queueKeyPrefix queue.toKey('')
35
- timestamp timestamp
36
- maxCheckTime max check time
37
- Events:
38
- 'stalled' with stalled job id.
39
22
  ]]
40
23
  local rcall = redis.call
41
24
  -- Includes
25
+ --[[
26
+ Function to add job in target list and add marker if needed.
27
+ ]]
28
+ -- Includes
29
+ --[[
30
+ Add marker if needed when a job is available.
31
+ ]]
32
+ local function addBaseMarkerIfNeeded(markerKey, isPaused)
33
+ if not isPaused then
34
+ rcall("ZADD", markerKey, 0, "0")
35
+ end
36
+ end
37
+ local function addJobInTargetList(targetKey, markerKey, pushCmd, isPaused, jobId)
38
+ rcall(pushCmd, targetKey, jobId)
39
+ addBaseMarkerIfNeeded(markerKey, isPaused)
40
+ end
42
41
  --[[
43
42
  Function to loop in batches.
44
43
  Just a bit of warning, some commands as ZREM
@@ -200,103 +199,107 @@ local function trimEvents(metaKey, eventStreamKey)
200
199
  rcall("XTRIM", eventStreamKey, "MAXLEN", "~", 10000)
201
200
  end
202
201
  end
203
- -- Check if we need to check for stalled jobs now.
204
- local function checkStalledJobs(stalledKey, waitKey, activeKey, failedKey,
205
- stalledCheckKey, metaKey, pausedKey,
206
- eventStreamKey, maxStalledJobCount,
207
- queueKeyPrefix, timestamp, maxCheckTime)
208
- if rcall("EXISTS", stalledCheckKey) == 1 then return {{}, {}} end
209
- rcall("SET", stalledCheckKey, timestamp, "PX", maxCheckTime)
210
- -- Trim events before emiting them to avoid trimming events emitted in this script
211
- trimEvents(metaKey, eventStreamKey)
212
- -- Move all stalled jobs to wait
213
- local stalling = rcall('SMEMBERS', stalledKey)
214
- local stalled = {}
215
- local failed = {}
216
- if (#stalling > 0) then
217
- rcall('DEL', stalledKey)
218
- local MAX_STALLED_JOB_COUNT = tonumber(maxStalledJobCount)
219
- -- Remove from active list
220
- for i, jobId in ipairs(stalling) do
221
- -- Markers in waitlist DEPRECATED in v5: Remove in v6.
222
- if string.sub(jobId, 1, 2) == "0:" then
223
- -- If the jobId is a delay marker ID we just remove it.
224
- rcall("LREM", activeKey, 1, jobId)
225
- else
226
- local jobKey = queueKeyPrefix .. jobId
227
- -- Check that the lock is also missing, then we can handle this job as really stalled.
228
- if (rcall("EXISTS", jobKey .. ":lock") == 0) then
229
- -- Remove from the active queue.
230
- local removed = rcall("LREM", activeKey, 1, jobId)
231
- if (removed > 0) then
232
- -- If this job has been stalled too many times, such as if it crashes the worker, then fail it.
233
- local stalledCount =
234
- rcall("HINCRBY", jobKey, "stalledCounter", 1)
235
- if (stalledCount > MAX_STALLED_JOB_COUNT) then
236
- local rawOpts = rcall("HGET", jobKey, "opts")
237
- local opts = cjson.decode(rawOpts)
238
- local removeOnFailType = type(opts["removeOnFail"])
239
- rcall("ZADD", failedKey, timestamp, jobId)
240
- local failedReason =
241
- "job stalled more than allowable limit"
242
- rcall("HMSET", jobKey, "failedReason", failedReason,
243
- "finishedOn", timestamp)
244
- rcall("XADD", eventStreamKey, "*", "event",
245
- "failed", "jobId", jobId, 'prev', 'active',
246
- 'failedReason', failedReason)
247
- if removeOnFailType == "number" then
248
- removeJobsByMaxCount(opts["removeOnFail"],
249
- failedKey, queueKeyPrefix)
250
- elseif removeOnFailType == "boolean" then
251
- if opts["removeOnFail"] then
252
- removeJob(jobId, false, queueKeyPrefix)
253
- rcall("ZREM", failedKey, jobId)
254
- end
255
- elseif removeOnFailType ~= "nil" then
256
- local maxAge = opts["removeOnFail"]["age"]
257
- local maxCount = opts["removeOnFail"]["count"]
258
- if maxAge ~= nil then
259
- removeJobsByMaxAge(timestamp, maxAge,
260
- failedKey, queueKeyPrefix)
261
- end
262
- if maxCount ~= nil and maxCount > 0 then
263
- removeJobsByMaxCount(maxCount, failedKey,
264
- queueKeyPrefix)
265
- end
202
+ local stalledKey = KEYS[1]
203
+ local waitKey = KEYS[2]
204
+ local activeKey = KEYS[3]
205
+ local failedKey = KEYS[4]
206
+ local stalledCheckKey = KEYS[5]
207
+ local metaKey = KEYS[6]
208
+ local pausedKey = KEYS[7]
209
+ local markerKey = KEYS[8]
210
+ local eventStreamKey = KEYS[9]
211
+ local maxStalledJobCount = ARGV[1]
212
+ local queueKeyPrefix = ARGV[2]
213
+ local timestamp = ARGV[3]
214
+ local maxCheckTime = ARGV[4]
215
+ if rcall("EXISTS", stalledCheckKey) == 1 then return {{}, {}} end
216
+ rcall("SET", stalledCheckKey, timestamp, "PX", maxCheckTime)
217
+ -- Trim events before emiting them to avoid trimming events emitted in this script
218
+ trimEvents(metaKey, eventStreamKey)
219
+ -- Move all stalled jobs to wait
220
+ local stalling = rcall('SMEMBERS', stalledKey)
221
+ local stalled = {}
222
+ local failed = {}
223
+ if (#stalling > 0) then
224
+ rcall('DEL', stalledKey)
225
+ local MAX_STALLED_JOB_COUNT = tonumber(maxStalledJobCount)
226
+ -- Remove from active list
227
+ for i, jobId in ipairs(stalling) do
228
+ -- Markers in waitlist DEPRECATED in v5: Remove in v6.
229
+ if string.sub(jobId, 1, 2) == "0:" then
230
+ -- If the jobId is a delay marker ID we just remove it.
231
+ rcall("LREM", activeKey, 1, jobId)
232
+ else
233
+ local jobKey = queueKeyPrefix .. jobId
234
+ -- Check that the lock is also missing, then we can handle this job as really stalled.
235
+ if (rcall("EXISTS", jobKey .. ":lock") == 0) then
236
+ -- Remove from the active queue.
237
+ local removed = rcall("LREM", activeKey, 1, jobId)
238
+ if (removed > 0) then
239
+ -- If this job has been stalled too many times, such as if it crashes the worker, then fail it.
240
+ local stalledCount =
241
+ rcall("HINCRBY", jobKey, "stalledCounter", 1)
242
+ if (stalledCount > MAX_STALLED_JOB_COUNT) then
243
+ local rawOpts = rcall("HGET", jobKey, "opts")
244
+ local opts = cjson.decode(rawOpts)
245
+ local removeOnFailType = type(opts["removeOnFail"])
246
+ rcall("ZADD", failedKey, timestamp, jobId)
247
+ local failedReason =
248
+ "job stalled more than allowable limit"
249
+ rcall("HMSET", jobKey, "failedReason", failedReason,
250
+ "finishedOn", timestamp)
251
+ rcall("XADD", eventStreamKey, "*", "event",
252
+ "failed", "jobId", jobId, 'prev', 'active',
253
+ 'failedReason', failedReason)
254
+ if removeOnFailType == "number" then
255
+ removeJobsByMaxCount(opts["removeOnFail"],
256
+ failedKey, queueKeyPrefix)
257
+ elseif removeOnFailType == "boolean" then
258
+ if opts["removeOnFail"] then
259
+ removeJob(jobId, false, queueKeyPrefix)
260
+ rcall("ZREM", failedKey, jobId)
261
+ end
262
+ elseif removeOnFailType ~= "nil" then
263
+ local maxAge = opts["removeOnFail"]["age"]
264
+ local maxCount = opts["removeOnFail"]["count"]
265
+ if maxAge ~= nil then
266
+ removeJobsByMaxAge(timestamp, maxAge,
267
+ failedKey, queueKeyPrefix)
268
+ end
269
+ if maxCount ~= nil and maxCount > 0 then
270
+ removeJobsByMaxCount(maxCount, failedKey,
271
+ queueKeyPrefix)
266
272
  end
267
- table.insert(failed, jobId)
268
- else
269
- local target =
270
- getTargetQueueList(metaKey, waitKey, pausedKey)
271
- -- Move the job back to the wait queue, to immediately be picked up by a waiting worker.
272
- rcall("RPUSH", target, jobId)
273
- rcall("XADD", eventStreamKey, "*", "event",
274
- "waiting", "jobId", jobId, 'prev', 'active')
275
- -- Emit the stalled event
276
- rcall("XADD", eventStreamKey, "*", "event",
277
- "stalled", "jobId", jobId)
278
- table.insert(stalled, jobId)
279
273
  end
274
+ table.insert(failed, jobId)
275
+ else
276
+ local target, isPaused=
277
+ getTargetQueueList(metaKey, waitKey, pausedKey)
278
+ -- Move the job back to the wait queue, to immediately be picked up by a waiting worker.
279
+ addJobInTargetList(target, markerKey, "RPUSH", isPaused, jobId)
280
+ rcall("XADD", eventStreamKey, "*", "event",
281
+ "waiting", "jobId", jobId, 'prev', 'active')
282
+ -- Emit the stalled event
283
+ rcall("XADD", eventStreamKey, "*", "event",
284
+ "stalled", "jobId", jobId)
285
+ table.insert(stalled, jobId)
280
286
  end
281
287
  end
282
288
  end
283
289
  end
284
290
  end
285
- -- Mark potentially stalled jobs
286
- local active = rcall('LRANGE', activeKey, 0, -1)
287
- if (#active > 0) then
288
- for from, to in batches(#active, 7000) do
289
- rcall('SADD', stalledKey, unpack(active, from, to))
290
- end
291
+ end
292
+ -- Mark potentially stalled jobs
293
+ local active = rcall('LRANGE', activeKey, 0, -1)
294
+ if (#active > 0) then
295
+ for from, to in batches(#active, 7000) do
296
+ rcall('SADD', stalledKey, unpack(active, from, to))
291
297
  end
292
- return {failed, stalled}
293
298
  end
294
- return checkStalledJobs(KEYS[1], KEYS[2], KEYS[3], KEYS[4], KEYS[5], KEYS[6],
295
- KEYS[7], KEYS[8], ARGV[1], ARGV[2], ARGV[3], ARGV[4])
296
- `;
299
+ return {failed, stalled}`;
297
300
  exports.moveStalledJobsToWait = {
298
301
  name: 'moveStalledJobsToWait',
299
302
  content,
300
- keys: 8,
303
+ keys: 9,
301
304
  };
302
- //# sourceMappingURL=moveStalledJobsToWait-8.js.map
305
+ //# sourceMappingURL=moveStalledJobsToWait-9.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"moveStalledJobsToWait-8.js","sourceRoot":"","sources":["../../../src/scripts/moveStalledJobsToWait-8.ts"],"names":[],"mappings":";;;AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAoSf,CAAC;AACW,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;yBAuSS,CAAC;AACb,QAAA,qBAAqB,GAAG;IACnC,IAAI,EAAE,uBAAuB;IAC7B,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
@@ -159,16 +159,31 @@ end
159
159
  'waiting'
160
160
  ]]
161
161
  -- Includes
162
+ --[[
163
+ Function to add job in target list and add marker if needed.
164
+ ]]
165
+ -- Includes
166
+ --[[
167
+ Add marker if needed when a job is available.
168
+ ]]
169
+ local function addBaseMarkerIfNeeded(markerKey, isPaused)
170
+ if not isPaused then
171
+ rcall("ZADD", markerKey, 0, "0")
172
+ end
173
+ end
174
+ local function addJobInTargetList(targetKey, markerKey, pushCmd, isPaused, jobId)
175
+ rcall(pushCmd, targetKey, jobId)
176
+ addBaseMarkerIfNeeded(markerKey, isPaused)
177
+ end
162
178
  --[[
163
179
  Function to add job considering priority.
164
180
  ]]
181
+ -- Includes
165
182
  local function addJobWithPriority(markerKey, prioritizedKey, priority, jobId, priorityCounterKey, isPaused)
166
183
  local prioCounter = rcall("INCR", priorityCounterKey)
167
184
  local score = priority * 0x100000000 + bit.band(prioCounter, 0xffffffffffff)
168
185
  rcall("ZADD", prioritizedKey, score, jobId)
169
- if not isPaused then
170
- rcall("ZADD", markerKey, 0, "0")
171
- end
186
+ addBaseMarkerIfNeeded(markerKey, isPaused)
172
187
  end
173
188
  -- Try to get as much as 1000 jobs at once
174
189
  local function promoteDelayedJobs(delayedKey, markerKey, targetKey, prioritizedKey,
@@ -182,10 +197,7 @@ local function promoteDelayedJobs(delayedKey, markerKey, targetKey, prioritizedK
182
197
  tonumber(rcall("HGET", jobKey, "priority")) or 0
183
198
  if priority == 0 then
184
199
  -- LIFO or FIFO
185
- rcall("LPUSH", targetKey, jobId)
186
- if not isPaused then
187
- rcall("ZADD", markerKey, 0, "0")
188
- end
200
+ addJobInTargetList(targetKey, markerKey, "LPUSH", isPaused, jobId)
189
201
  else
190
202
  addJobWithPriority(markerKey, prioritizedKey, priority,
191
203
  jobId, priorityCounterKey, isPaused)
@@ -1 +1 @@
1
- {"version":3,"file":"moveToActive-11.js","sourceRoot":"","sources":["../../../src/scripts/moveToActive-11.ts"],"names":[],"mappings":";;;AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAoOf,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgPf,CAAC;AACW,QAAA,YAAY,GAAG;IAC1B,IAAI,EAAE,cAAc;IACpB,OAAO;IACP,IAAI,EAAE,EAAE;CACT,CAAC"}
@@ -29,7 +29,7 @@ local rcall = redis.call
29
29
  -- Includes
30
30
  --[[
31
31
  Add delay marker if needed.
32
- ]]
32
+ ]]
33
33
  -- Includes
34
34
  --[[
35
35
  Function to return the next delayed job timestamp.