bullmq 5.53.1 → 5.53.2

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 (30) hide show
  1. package/dist/cjs/classes/scripts.js +0 -1
  2. package/dist/cjs/classes/scripts.js.map +1 -1
  3. package/dist/cjs/classes/worker.js +1 -21
  4. package/dist/cjs/classes/worker.js.map +1 -1
  5. package/dist/cjs/commands/{moveStalledJobsToWait-9.lua → moveStalledJobsToWait-8.lua} +23 -40
  6. package/dist/cjs/scripts/index.js +1 -1
  7. package/dist/cjs/scripts/moveStalledJobsToWait-8.js +171 -0
  8. package/dist/cjs/scripts/moveStalledJobsToWait-8.js.map +1 -0
  9. package/dist/cjs/tsconfig-cjs.tsbuildinfo +1 -1
  10. package/dist/cjs/version.js +1 -1
  11. package/dist/esm/classes/scripts.d.ts +1 -1
  12. package/dist/esm/classes/scripts.js +0 -1
  13. package/dist/esm/classes/scripts.js.map +1 -1
  14. package/dist/esm/classes/worker.d.ts +0 -1
  15. package/dist/esm/classes/worker.js +1 -21
  16. package/dist/esm/classes/worker.js.map +1 -1
  17. package/dist/esm/commands/{moveStalledJobsToWait-9.lua → moveStalledJobsToWait-8.lua} +23 -40
  18. package/dist/esm/scripts/index.d.ts +1 -1
  19. package/dist/esm/scripts/index.js +1 -1
  20. package/dist/esm/scripts/moveStalledJobsToWait-8.js +168 -0
  21. package/dist/esm/scripts/moveStalledJobsToWait-8.js.map +1 -0
  22. package/dist/esm/tsconfig.tsbuildinfo +1 -1
  23. package/dist/esm/version.d.ts +1 -1
  24. package/dist/esm/version.js +1 -1
  25. package/package.json +1 -1
  26. package/dist/cjs/scripts/moveStalledJobsToWait-9.js +0 -563
  27. package/dist/cjs/scripts/moveStalledJobsToWait-9.js.map +0 -1
  28. package/dist/esm/scripts/moveStalledJobsToWait-9.js +0 -560
  29. package/dist/esm/scripts/moveStalledJobsToWait-9.js.map +0 -1
  30. /package/dist/esm/scripts/{moveStalledJobsToWait-9.d.ts → moveStalledJobsToWait-8.d.ts} +0 -0
@@ -1,560 +0,0 @@
1
- const content = `--[[
2
- Move stalled jobs to wait.
3
- Input:
4
- KEYS[1] 'stalled' (SET)
5
- KEYS[2] 'wait', (LIST)
6
- KEYS[3] 'active', (LIST)
7
- KEYS[4] 'failed', (ZSET)
8
- KEYS[5] 'stalled-check', (KEY)
9
- KEYS[6] 'meta', (KEY)
10
- KEYS[7] 'paused', (LIST)
11
- KEYS[8] 'marker'
12
- KEYS[9] 'event stream' (STREAM)
13
- ARGV[1] Max stalled job count
14
- ARGV[2] queue.toKey('')
15
- ARGV[3] timestamp
16
- ARGV[4] max check time
17
- Events:
18
- 'stalled' with stalled job id.
19
- ]]
20
- local rcall = redis.call
21
- -- Includes
22
- --[[
23
- Function to add job in target list and add marker if needed.
24
- ]]
25
- -- Includes
26
- --[[
27
- Add marker if needed when a job is available.
28
- ]]
29
- local function addBaseMarkerIfNeeded(markerKey, isPausedOrMaxed)
30
- if not isPausedOrMaxed then
31
- rcall("ZADD", markerKey, 0, "0")
32
- end
33
- end
34
- local function addJobInTargetList(targetKey, markerKey, pushCmd, isPausedOrMaxed, jobId)
35
- rcall(pushCmd, targetKey, jobId)
36
- addBaseMarkerIfNeeded(markerKey, isPausedOrMaxed)
37
- end
38
- --[[
39
- Function to loop in batches.
40
- Just a bit of warning, some commands as ZREM
41
- could receive a maximum of 7000 parameters per call.
42
- ]]
43
- local function batches(n, batchSize)
44
- local i = 0
45
- return function()
46
- local from = i * batchSize + 1
47
- i = i + 1
48
- if (from <= n) then
49
- local to = math.min(from + batchSize - 1, n)
50
- return from, to
51
- end
52
- end
53
- end
54
- --[[
55
- Function to check for the meta.paused key to decide if we are paused or not
56
- (since an empty list and !EXISTS are not really the same).
57
- ]]
58
- local function getTargetQueueList(queueMetaKey, activeKey, waitKey, pausedKey)
59
- local queueAttributes = rcall("HMGET", queueMetaKey, "paused", "concurrency")
60
- if queueAttributes[1] then
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
71
- end
72
- return waitKey, false
73
- end
74
- --[[
75
- Function to recursively move from waitingChildren to failed.
76
- ]]
77
- -- Includes
78
- --[[
79
- Validate and move parent to a wait status (waiting, delayed or prioritized)
80
- if no pending dependencies.
81
- ]]
82
- -- Includes
83
- --[[
84
- Validate and move parent to a wait status (waiting, delayed or prioritized) if needed.
85
- ]]
86
- -- Includes
87
- --[[
88
- Move parent to a wait status (wait, prioritized or delayed)
89
- ]]
90
- -- Includes
91
- --[[
92
- Add delay marker if needed.
93
- ]]
94
- -- Includes
95
- --[[
96
- Function to return the next delayed job timestamp.
97
- ]]
98
- local function getNextDelayedTimestamp(delayedKey)
99
- local result = rcall("ZRANGE", delayedKey, 0, 0, "WITHSCORES")
100
- if #result then
101
- local nextTimestamp = tonumber(result[2])
102
- if nextTimestamp ~= nil then
103
- return nextTimestamp / 0x1000
104
- end
105
- end
106
- end
107
- local function addDelayMarkerIfNeeded(markerKey, delayedKey)
108
- local nextTimestamp = getNextDelayedTimestamp(delayedKey)
109
- if nextTimestamp ~= nil then
110
- -- Replace the score of the marker with the newest known
111
- -- next timestamp.
112
- rcall("ZADD", markerKey, nextTimestamp, "1")
113
- end
114
- end
115
- --[[
116
- Function to add job considering priority.
117
- ]]
118
- -- Includes
119
- --[[
120
- Function to get priority score.
121
- ]]
122
- local function getPriorityScore(priority, priorityCounterKey)
123
- local prioCounter = rcall("INCR", priorityCounterKey)
124
- return priority * 0x100000000 + prioCounter % 0x100000000
125
- end
126
- local function addJobWithPriority(markerKey, prioritizedKey, priority, jobId, priorityCounterKey,
127
- isPausedOrMaxed)
128
- local score = getPriorityScore(priority, priorityCounterKey)
129
- rcall("ZADD", prioritizedKey, score, jobId)
130
- addBaseMarkerIfNeeded(markerKey, isPausedOrMaxed)
131
- end
132
- --[[
133
- Function to check if queue is paused or maxed
134
- (since an empty list and !EXISTS are not really the same).
135
- ]]
136
- local function isQueuePausedOrMaxed(queueMetaKey, activeKey)
137
- local queueAttributes = rcall("HMGET", queueMetaKey, "paused", "concurrency")
138
- if queueAttributes[1] then
139
- return true
140
- else
141
- if queueAttributes[2] then
142
- local activeCount = rcall("LLEN", activeKey)
143
- return activeCount >= tonumber(queueAttributes[2])
144
- end
145
- end
146
- return false
147
- end
148
- local function moveParentToWait(parentQueueKey, parentKey, parentId, timestamp)
149
- local parentWaitKey = parentQueueKey .. ":wait"
150
- local parentPausedKey = parentQueueKey .. ":paused"
151
- local parentActiveKey = parentQueueKey .. ":active"
152
- local parentMetaKey = parentQueueKey .. ":meta"
153
- local parentMarkerKey = parentQueueKey .. ":marker"
154
- local jobAttributes = rcall("HMGET", parentKey, "priority", "delay")
155
- local priority = tonumber(jobAttributes[1]) or 0
156
- local delay = tonumber(jobAttributes[2]) or 0
157
- if delay > 0 then
158
- local delayedTimestamp = tonumber(timestamp) + delay
159
- local score = delayedTimestamp * 0x1000
160
- local parentDelayedKey = parentQueueKey .. ":delayed"
161
- rcall("ZADD", parentDelayedKey, score, parentId)
162
- rcall("XADD", parentQueueKey .. ":events", "*", "event", "delayed", "jobId", parentId, "delay",
163
- delayedTimestamp)
164
- addDelayMarkerIfNeeded(parentMarkerKey, parentDelayedKey)
165
- else
166
- if priority == 0 then
167
- local parentTarget, isParentPausedOrMaxed = getTargetQueueList(parentMetaKey, parentActiveKey,
168
- parentWaitKey, parentPausedKey)
169
- addJobInTargetList(parentTarget, parentMarkerKey, "RPUSH", isParentPausedOrMaxed, parentId)
170
- else
171
- local isPausedOrMaxed = isQueuePausedOrMaxed(parentMetaKey, parentActiveKey)
172
- addJobWithPriority(parentMarkerKey, parentQueueKey .. ":prioritized", priority, parentId,
173
- parentQueueKey .. ":pc", isPausedOrMaxed)
174
- end
175
- rcall("XADD", parentQueueKey .. ":events", "*", "event", "waiting", "jobId", parentId, "prev",
176
- "waiting-children")
177
- end
178
- end
179
- local function moveParentToWaitIfNeeded(parentQueueKey, parentKey, parentId, timestamp)
180
- if rcall("EXISTS", parentKey) == 1 then
181
- local parentWaitingChildrenKey = parentQueueKey .. ":waiting-children"
182
- if rcall("ZSCORE", parentWaitingChildrenKey, parentId) then
183
- rcall("ZREM", parentWaitingChildrenKey, parentId)
184
- moveParentToWait(parentQueueKey, parentKey, parentId, timestamp)
185
- end
186
- end
187
- end
188
- local function moveParentToWaitIfNoPendingDependencies(parentQueueKey, parentDependenciesKey, parentKey,
189
- parentId, timestamp)
190
- local doNotHavePendingDependencies = rcall("SCARD", parentDependenciesKey) == 0
191
- if doNotHavePendingDependencies then
192
- moveParentToWaitIfNeeded(parentQueueKey, parentKey, parentId, timestamp)
193
- end
194
- end
195
- --[[
196
- Functions to remove jobs when removeOnFail option is provided.
197
- ]]
198
- -- Includes
199
- --[[
200
- Function to remove job.
201
- ]]
202
- -- Includes
203
- --[[
204
- Function to remove deduplication key if needed
205
- when a job is being removed.
206
- ]]
207
- local function removeDeduplicationKeyIfNeededOnRemoval(prefixKey,
208
- jobKey, jobId)
209
- local deduplicationId = rcall("HGET", jobKey, "deid")
210
- if deduplicationId then
211
- local deduplicationKey = prefixKey .. "de:" .. deduplicationId
212
- local currentJobId = rcall('GET', deduplicationKey)
213
- if currentJobId and currentJobId == jobId then
214
- return rcall("DEL", deduplicationKey)
215
- end
216
- end
217
- end
218
- --[[
219
- Function to remove job keys.
220
- ]]
221
- local function removeJobKeys(jobKey)
222
- return rcall("DEL", jobKey, jobKey .. ':logs', jobKey .. ':dependencies',
223
- jobKey .. ':processed', jobKey .. ':failed', jobKey .. ':unsuccessful')
224
- end
225
- --[[
226
- Check if this job has a parent. If so we will just remove it from
227
- the parent child list, but if it is the last child we should move the parent to "wait/paused"
228
- which requires code from "moveToFinished"
229
- ]]
230
- -- Includes
231
- --[[
232
- Functions to destructure job key.
233
- Just a bit of warning, these functions may be a bit slow and affect performance significantly.
234
- ]]
235
- local getJobIdFromKey = function (jobKey)
236
- return string.match(jobKey, ".*:(.*)")
237
- end
238
- local getJobKeyPrefix = function (jobKey, jobId)
239
- return string.sub(jobKey, 0, #jobKey - #jobId)
240
- end
241
- local function _moveParentToWait(parentPrefix, parentId, emitEvent)
242
- local parentTarget, isPausedOrMaxed = getTargetQueueList(parentPrefix .. "meta", parentPrefix .. "active",
243
- parentPrefix .. "wait", parentPrefix .. "paused")
244
- addJobInTargetList(parentTarget, parentPrefix .. "marker", "RPUSH", isPausedOrMaxed, parentId)
245
- if emitEvent then
246
- local parentEventStream = parentPrefix .. "events"
247
- rcall("XADD", parentEventStream, "*", "event", "waiting", "jobId", parentId, "prev", "waiting-children")
248
- end
249
- end
250
- local function removeParentDependencyKey(jobKey, hard, parentKey, baseKey, debounceId)
251
- if parentKey then
252
- local parentDependenciesKey = parentKey .. ":dependencies"
253
- local result = rcall("SREM", parentDependenciesKey, jobKey)
254
- if result > 0 then
255
- local pendingDependencies = rcall("SCARD", parentDependenciesKey)
256
- if pendingDependencies == 0 then
257
- local parentId = getJobIdFromKey(parentKey)
258
- local parentPrefix = getJobKeyPrefix(parentKey, parentId)
259
- local numRemovedElements = rcall("ZREM", parentPrefix .. "waiting-children", parentId)
260
- if numRemovedElements == 1 then
261
- if hard then -- remove parent in same queue
262
- if parentPrefix == baseKey then
263
- removeParentDependencyKey(parentKey, hard, nil, baseKey, nil)
264
- removeJobKeys(parentKey)
265
- if debounceId then
266
- rcall("DEL", parentPrefix .. "de:" .. debounceId)
267
- end
268
- else
269
- _moveParentToWait(parentPrefix, parentId)
270
- end
271
- else
272
- _moveParentToWait(parentPrefix, parentId, true)
273
- end
274
- end
275
- end
276
- return true
277
- end
278
- else
279
- local parentAttributes = rcall("HMGET", jobKey, "parentKey", "deid")
280
- local missedParentKey = parentAttributes[1]
281
- if( (type(missedParentKey) == "string") and missedParentKey ~= ""
282
- and (rcall("EXISTS", missedParentKey) == 1)) then
283
- local parentDependenciesKey = missedParentKey .. ":dependencies"
284
- local result = rcall("SREM", parentDependenciesKey, jobKey)
285
- if result > 0 then
286
- local pendingDependencies = rcall("SCARD", parentDependenciesKey)
287
- if pendingDependencies == 0 then
288
- local parentId = getJobIdFromKey(missedParentKey)
289
- local parentPrefix = getJobKeyPrefix(missedParentKey, parentId)
290
- local numRemovedElements = rcall("ZREM", parentPrefix .. "waiting-children", parentId)
291
- if numRemovedElements == 1 then
292
- if hard then
293
- if parentPrefix == baseKey then
294
- removeParentDependencyKey(missedParentKey, hard, nil, baseKey, nil)
295
- removeJobKeys(missedParentKey)
296
- if parentAttributes[2] then
297
- rcall("DEL", parentPrefix .. "de:" .. parentAttributes[2])
298
- end
299
- else
300
- _moveParentToWait(parentPrefix, parentId)
301
- end
302
- else
303
- _moveParentToWait(parentPrefix, parentId, true)
304
- end
305
- end
306
- end
307
- return true
308
- end
309
- end
310
- end
311
- return false
312
- end
313
- local function removeJob(jobId, hard, baseKey, shouldRemoveDeduplicationKey)
314
- local jobKey = baseKey .. jobId
315
- removeParentDependencyKey(jobKey, hard, nil, baseKey)
316
- if shouldRemoveDeduplicationKey then
317
- removeDeduplicationKeyIfNeededOnRemoval(baseKey, jobKey, jobId)
318
- end
319
- removeJobKeys(jobKey)
320
- end
321
- --[[
322
- Functions to remove jobs by max age.
323
- ]]
324
- -- Includes
325
- local function removeJobsByMaxAge(timestamp, maxAge, targetSet, prefix,
326
- shouldRemoveDebounceKey)
327
- local start = timestamp - maxAge * 1000
328
- local jobIds = rcall("ZREVRANGEBYSCORE", targetSet, start, "-inf")
329
- for i, jobId in ipairs(jobIds) do
330
- removeJob(jobId, false, prefix, false --[[remove debounce key]])
331
- end
332
- rcall("ZREMRANGEBYSCORE", targetSet, "-inf", start)
333
- end
334
- --[[
335
- Functions to remove jobs by max count.
336
- ]]
337
- -- Includes
338
- local function removeJobsByMaxCount(maxCount, targetSet, prefix)
339
- local start = maxCount
340
- local jobIds = rcall("ZREVRANGE", targetSet, start, -1)
341
- for i, jobId in ipairs(jobIds) do
342
- removeJob(jobId, false, prefix, false --[[remove debounce key]])
343
- end
344
- rcall("ZREMRANGEBYRANK", targetSet, 0, -(maxCount + 1))
345
- end
346
- local function removeJobsOnFail(queueKeyPrefix, failedKey, jobId, opts, timestamp)
347
- local removeOnFailType = type(opts["removeOnFail"])
348
- if removeOnFailType == "number" then
349
- removeJobsByMaxCount(opts["removeOnFail"],
350
- failedKey, queueKeyPrefix)
351
- elseif removeOnFailType == "boolean" then
352
- if opts["removeOnFail"] then
353
- removeJob(jobId, false, queueKeyPrefix,
354
- false --[[remove debounce key]])
355
- rcall("ZREM", failedKey, jobId)
356
- end
357
- elseif removeOnFailType ~= "nil" then
358
- local maxAge = opts["removeOnFail"]["age"]
359
- local maxCount = opts["removeOnFail"]["count"]
360
- if maxAge ~= nil then
361
- removeJobsByMaxAge(timestamp, maxAge,
362
- failedKey, queueKeyPrefix)
363
- end
364
- if maxCount ~= nil and maxCount > 0 then
365
- removeJobsByMaxCount(maxCount, failedKey,
366
- queueKeyPrefix)
367
- end
368
- end
369
- end
370
- local moveParentToFailedIfNeeded = function (parentQueueKey, parentKey, parentId, jobIdKey, timestamp)
371
- if rcall("EXISTS", parentKey) == 1 then
372
- local parentWaitingChildrenKey = parentQueueKey .. ":waiting-children"
373
- local parentDelayedKey = parentQueueKey .. ":delayed"
374
- local parentPrioritizedKey = parentQueueKey .. ":prioritized"
375
- local parentWaitingChildrenOrDelayedKey
376
- local prevState
377
- if rcall("ZSCORE", parentWaitingChildrenKey, parentId) then
378
- parentWaitingChildrenOrDelayedKey = parentWaitingChildrenKey
379
- prevState = "waiting-children"
380
- elseif rcall("ZSCORE", parentDelayedKey, parentId) then
381
- parentWaitingChildrenOrDelayedKey = parentDelayedKey
382
- prevState = "delayed"
383
- rcall("HSET", parentKey, "delay", 0)
384
- end
385
- if parentWaitingChildrenOrDelayedKey then
386
- rcall("ZREM", parentWaitingChildrenOrDelayedKey, parentId)
387
- local parentQueuePrefix = parentQueueKey .. ":"
388
- local parentFailedKey = parentQueueKey .. ":failed"
389
- local deferredFailure = "child " .. jobIdKey .. " failed"
390
- rcall("HSET", parentKey, "defa", deferredFailure)
391
- moveParentToWait(parentQueueKey, parentKey, parentId, timestamp)
392
- else
393
- if not rcall("ZSCORE", parentQueueKey .. ":failed", parentId) then
394
- local deferredFailure = "child " .. jobIdKey .. " failed"
395
- rcall("HSET", parentKey, "defa", deferredFailure)
396
- end
397
- end
398
- end
399
- end
400
- local moveChildFromDependenciesIfNeeded = function (rawParentData, childKey, failedReason, timestamp)
401
- if rawParentData then
402
- local parentData = cjson.decode(rawParentData)
403
- local parentKey = parentData['queueKey'] .. ':' .. parentData['id']
404
- local parentDependenciesChildrenKey = parentKey .. ":dependencies"
405
- if parentData['fpof'] then
406
- if rcall("SREM", parentDependenciesChildrenKey, childKey) == 1 then
407
- local parentUnsuccesssfulChildrenKey = parentKey .. ":unsuccessful"
408
- rcall("ZADD", parentUnsuccesssfulChildrenKey, timestamp, childKey)
409
- moveParentToFailedIfNeeded(
410
- parentData['queueKey'],
411
- parentKey,
412
- parentData['id'],
413
- childKey,
414
- timestamp
415
- )
416
- end
417
- elseif parentData['cpof'] then
418
- if rcall("SREM", parentDependenciesChildrenKey, childKey) == 1 then
419
- local parentFailedChildrenKey = parentKey .. ":failed"
420
- rcall("HSET", parentFailedChildrenKey, childKey, failedReason)
421
- moveParentToWaitIfNeeded(parentData['queueKey'], parentKey, parentData['id'], timestamp)
422
- end
423
- elseif parentData['idof'] or parentData['rdof'] then
424
- if rcall("SREM", parentDependenciesChildrenKey, childKey) == 1 then
425
- moveParentToWaitIfNoPendingDependencies(parentData['queueKey'], parentDependenciesChildrenKey,
426
- parentKey, parentData['id'], timestamp)
427
- if parentData['idof'] then
428
- local parentFailedChildrenKey = parentKey .. ":failed"
429
- rcall("HSET", parentFailedChildrenKey, childKey, failedReason)
430
- end
431
- end
432
- end
433
- end
434
- end
435
- --[[
436
- Function to remove deduplication key if needed
437
- when a job is moved to completed or failed states.
438
- ]]
439
- local function removeDeduplicationKeyIfNeededOnFinalization(prefixKey,
440
- deduplicationId, jobId)
441
- if deduplicationId then
442
- local deduplicationKey = prefixKey .. "de:" .. deduplicationId
443
- local pttl = rcall("PTTL", deduplicationKey)
444
- if pttl == 0 then
445
- return rcall("DEL", deduplicationKey)
446
- end
447
- if pttl == -1 then
448
- local currentJobId = rcall('GET', deduplicationKey)
449
- if currentJobId and currentJobId == jobId then
450
- return rcall("DEL", deduplicationKey)
451
- end
452
- end
453
- end
454
- end
455
- --[[
456
- Function to trim events, default 10000.
457
- ]]
458
- -- Includes
459
- --[[
460
- Function to get max events value or set by default 10000.
461
- ]]
462
- local function getOrSetMaxEvents(metaKey)
463
- local maxEvents = rcall("HGET", metaKey, "opts.maxLenEvents")
464
- if not maxEvents then
465
- maxEvents = 10000
466
- rcall("HSET", metaKey, "opts.maxLenEvents", maxEvents)
467
- end
468
- return maxEvents
469
- end
470
- local function trimEvents(metaKey, eventStreamKey)
471
- local maxEvents = getOrSetMaxEvents(metaKey)
472
- if maxEvents then
473
- rcall("XTRIM", eventStreamKey, "MAXLEN", "~", maxEvents)
474
- else
475
- rcall("XTRIM", eventStreamKey, "MAXLEN", "~", 10000)
476
- end
477
- end
478
- local stalledKey = KEYS[1]
479
- local waitKey = KEYS[2]
480
- local activeKey = KEYS[3]
481
- local failedKey = KEYS[4]
482
- local stalledCheckKey = KEYS[5]
483
- local metaKey = KEYS[6]
484
- local pausedKey = KEYS[7]
485
- local markerKey = KEYS[8]
486
- local eventStreamKey = KEYS[9]
487
- local maxStalledJobCount = tonumber(ARGV[1])
488
- local queueKeyPrefix = ARGV[2]
489
- local timestamp = ARGV[3]
490
- local maxCheckTime = ARGV[4]
491
- if rcall("EXISTS", stalledCheckKey) == 1 then
492
- return {{}, {}}
493
- end
494
- rcall("SET", stalledCheckKey, timestamp, "PX", maxCheckTime)
495
- -- Trim events before emiting them to avoid trimming events emitted in this script
496
- trimEvents(metaKey, eventStreamKey)
497
- -- Move all stalled jobs to wait
498
- local stalling = rcall('SMEMBERS', stalledKey)
499
- local stalled = {}
500
- local failed = {}
501
- if (#stalling > 0) then
502
- rcall('DEL', stalledKey)
503
- -- Remove from active list
504
- for i, jobId in ipairs(stalling) do
505
- -- Markers in waitlist DEPRECATED in v5: Remove in v6.
506
- if string.sub(jobId, 1, 2) == "0:" then
507
- -- If the jobId is a delay marker ID we just remove it.
508
- rcall("LREM", activeKey, 1, jobId)
509
- else
510
- local jobKey = queueKeyPrefix .. jobId
511
- -- Check that the lock is also missing, then we can handle this job as really stalled.
512
- if (rcall("EXISTS", jobKey .. ":lock") == 0) then
513
- -- Remove from the active queue.
514
- local removed = rcall("LREM", activeKey, 1, jobId)
515
- if (removed > 0) then
516
- -- If this job has been stalled too many times, such as if it crashes the worker, then fail it.
517
- local stalledCount = rcall("HINCRBY", jobKey, "stc", 1)
518
- if (stalledCount > maxStalledJobCount) then
519
- local jobAttributes = rcall("HMGET", jobKey, "opts", "parent", "deid")
520
- local rawOpts = jobAttributes[1]
521
- local rawParentData = jobAttributes[2]
522
- local opts = cjson.decode(rawOpts)
523
- rcall("ZADD", failedKey, timestamp, jobId)
524
- removeDeduplicationKeyIfNeededOnFinalization(queueKeyPrefix, jobAttributes[3], jobId)
525
- local failedReason = "job stalled more than allowable limit"
526
- rcall("HMSET", jobKey, "failedReason", failedReason, "finishedOn", timestamp)
527
- rcall("XADD", eventStreamKey, "*", "event", "failed", "jobId", jobId, 'prev', 'active',
528
- 'failedReason', failedReason)
529
- moveChildFromDependenciesIfNeeded(rawParentData, jobKey, failedReason, timestamp)
530
- removeJobsOnFail(queueKeyPrefix, failedKey, jobId, opts, timestamp)
531
- table.insert(failed, jobId)
532
- else
533
- local target, isPausedOrMaxed = getTargetQueueList(metaKey, activeKey, waitKey, pausedKey)
534
- -- Move the job back to the wait queue, to immediately be picked up by a waiting worker.
535
- addJobInTargetList(target, markerKey, "RPUSH", isPausedOrMaxed, jobId)
536
- rcall("XADD", eventStreamKey, "*", "event", "waiting", "jobId", jobId, 'prev', 'active')
537
- -- Emit the stalled event
538
- rcall("XADD", eventStreamKey, "*", "event", "stalled", "jobId", jobId)
539
- table.insert(stalled, jobId)
540
- end
541
- end
542
- end
543
- end
544
- end
545
- end
546
- -- Mark potentially stalled jobs
547
- local active = rcall('LRANGE', activeKey, 0, -1)
548
- if (#active > 0) then
549
- for from, to in batches(#active, 7000) do
550
- rcall('SADD', stalledKey, unpack(active, from, to))
551
- end
552
- end
553
- return {failed, stalled}
554
- `;
555
- export const moveStalledJobsToWait = {
556
- name: 'moveStalledJobsToWait',
557
- content,
558
- keys: 9,
559
- };
560
- //# sourceMappingURL=moveStalledJobsToWait-9.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"moveStalledJobsToWait-9.js","sourceRoot":"","sources":["../../../src/scripts/moveStalledJobsToWait-9.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyiBf,CAAC;AACF,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,IAAI,EAAE,uBAAuB;IAC7B,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}