@tachybase/plugin-print-template 1.3.23 → 1.3.25

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 (41) hide show
  1. package/dist/externalVersion.js +2 -2
  2. package/dist/node_modules/bullmq/dist/cjs/classes/queue.js +4 -2
  3. package/dist/node_modules/bullmq/dist/cjs/classes/scripts.js +3 -3
  4. package/dist/node_modules/bullmq/dist/cjs/classes/worker.js +8 -9
  5. package/dist/node_modules/bullmq/dist/cjs/commands/includes/moveJobToWait.lua +15 -0
  6. package/dist/node_modules/bullmq/dist/cjs/commands/moveJobFromActiveToWait-9.lua +5 -1
  7. package/dist/node_modules/bullmq/dist/cjs/commands/moveStalledJobsToWait-8.lua +3 -11
  8. package/dist/node_modules/bullmq/dist/cjs/commands/{moveToWaitingChildren-8.lua → moveToWaitingChildren-7.lua} +29 -40
  9. package/dist/node_modules/bullmq/dist/cjs/enums/error-code.js +1 -1
  10. package/dist/node_modules/bullmq/dist/cjs/index.js +1 -1
  11. package/dist/node_modules/bullmq/dist/cjs/scripts/index.js +1 -1
  12. package/dist/node_modules/bullmq/dist/cjs/scripts/moveJobFromActiveToWait-9.js +5 -1
  13. package/dist/node_modules/bullmq/dist/cjs/scripts/moveStalledJobsToWait-8.js +12 -8
  14. package/dist/node_modules/bullmq/dist/cjs/scripts/moveToWaitingChildren-7.js +107 -0
  15. package/dist/node_modules/bullmq/dist/cjs/tsconfig-cjs.tsbuildinfo +1 -1
  16. package/dist/node_modules/bullmq/dist/cjs/version.js +1 -1
  17. package/dist/node_modules/bullmq/dist/esm/classes/queue.d.ts +1 -1
  18. package/dist/node_modules/bullmq/dist/esm/classes/queue.js +4 -2
  19. package/dist/node_modules/bullmq/dist/esm/classes/scripts.js +3 -3
  20. package/dist/node_modules/bullmq/dist/esm/classes/worker.js +8 -9
  21. package/dist/node_modules/bullmq/dist/esm/commands/includes/moveJobToWait.lua +15 -0
  22. package/dist/node_modules/bullmq/dist/esm/commands/moveJobFromActiveToWait-9.lua +5 -1
  23. package/dist/node_modules/bullmq/dist/esm/commands/moveStalledJobsToWait-8.lua +3 -11
  24. package/dist/node_modules/bullmq/dist/esm/commands/{moveToWaitingChildren-8.lua → moveToWaitingChildren-7.lua} +29 -40
  25. package/dist/node_modules/bullmq/dist/esm/enums/error-code.d.ts +1 -1
  26. package/dist/node_modules/bullmq/dist/esm/enums/error-code.js +1 -1
  27. package/dist/node_modules/bullmq/dist/esm/scripts/index.d.ts +1 -1
  28. package/dist/node_modules/bullmq/dist/esm/scripts/index.js +1 -1
  29. package/dist/node_modules/bullmq/dist/esm/scripts/moveJobFromActiveToWait-9.js +5 -1
  30. package/dist/node_modules/bullmq/dist/esm/scripts/moveStalledJobsToWait-8.js +12 -8
  31. package/dist/node_modules/bullmq/dist/esm/scripts/moveToWaitingChildren-7.js +104 -0
  32. package/dist/node_modules/bullmq/dist/esm/tsconfig.tsbuildinfo +1 -1
  33. package/dist/node_modules/bullmq/dist/esm/version.d.ts +1 -1
  34. package/dist/node_modules/bullmq/dist/esm/version.js +1 -1
  35. package/dist/node_modules/bullmq/package.json +1 -1
  36. package/dist/node_modules/docxtemplater/package.json +1 -1
  37. package/dist/node_modules/pizzip/package.json +1 -1
  38. package/package.json +6 -6
  39. package/dist/node_modules/bullmq/dist/cjs/scripts/moveToWaitingChildren-8.js +0 -529
  40. package/dist/node_modules/bullmq/dist/esm/scripts/moveToWaitingChildren-8.js +0 -526
  41. /package/dist/node_modules/bullmq/dist/esm/scripts/{moveToWaitingChildren-8.d.ts → moveToWaitingChildren-7.d.ts} +0 -0
@@ -1,529 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.moveToWaitingChildren = void 0;
4
- const content = `--[[
5
- Moves job from active to waiting children set.
6
- Input:
7
- KEYS[1] active key
8
- KEYS[2] wait-children key
9
- KEYS[3] job key
10
- KEYS[4] job dependencies key
11
- KEYS[5] job unsuccessful key
12
- KEYS[6] stalled key
13
- KEYS[7] failed key
14
- KEYS[8] events key
15
- ARGV[1] token
16
- ARGV[2] child key
17
- ARGV[3] timestamp
18
- ARGV[4] jobId
19
- ARGV[5] prefix
20
- Output:
21
- 0 - OK
22
- 1 - There are not pending dependencies.
23
- -1 - Missing job.
24
- -2 - Missing lock
25
- -3 - Job not in active set
26
- ]]
27
- local rcall = redis.call
28
- local activeKey = KEYS[1]
29
- local waitingChildrenKey = KEYS[2]
30
- local jobKey = KEYS[3]
31
- local jobDependenciesKey = KEYS[4]
32
- local jobUnsuccessfulKey = KEYS[5]
33
- local stalledKey = KEYS[6]
34
- local failedKey = KEYS[7]
35
- local timestamp = ARGV[3]
36
- local jobId = ARGV[4]
37
- --- Includes
38
- --[[
39
- Function to recursively move from waitingChildren to failed.
40
- ]]
41
- -- Includes
42
- --[[
43
- Validate and move parent to a wait status (waiting, delayed or prioritized)
44
- if no pending dependencies.
45
- ]]
46
- -- Includes
47
- --[[
48
- Validate and move parent to a wait status (waiting, delayed or prioritized) if needed.
49
- ]]
50
- -- Includes
51
- --[[
52
- Move parent to a wait status (wait, prioritized or delayed)
53
- ]]
54
- -- Includes
55
- --[[
56
- Add delay marker if needed.
57
- ]]
58
- -- Includes
59
- --[[
60
- Function to return the next delayed job timestamp.
61
- ]]
62
- local function getNextDelayedTimestamp(delayedKey)
63
- local result = rcall("ZRANGE", delayedKey, 0, 0, "WITHSCORES")
64
- if #result then
65
- local nextTimestamp = tonumber(result[2])
66
- if nextTimestamp ~= nil then
67
- return nextTimestamp / 0x1000
68
- end
69
- end
70
- end
71
- local function addDelayMarkerIfNeeded(markerKey, delayedKey)
72
- local nextTimestamp = getNextDelayedTimestamp(delayedKey)
73
- if nextTimestamp ~= nil then
74
- -- Replace the score of the marker with the newest known
75
- -- next timestamp.
76
- rcall("ZADD", markerKey, nextTimestamp, "1")
77
- end
78
- end
79
- --[[
80
- Function to add job in target list and add marker if needed.
81
- ]]
82
- -- Includes
83
- --[[
84
- Add marker if needed when a job is available.
85
- ]]
86
- local function addBaseMarkerIfNeeded(markerKey, isPausedOrMaxed)
87
- if not isPausedOrMaxed then
88
- rcall("ZADD", markerKey, 0, "0")
89
- end
90
- end
91
- local function addJobInTargetList(targetKey, markerKey, pushCmd, isPausedOrMaxed, jobId)
92
- rcall(pushCmd, targetKey, jobId)
93
- addBaseMarkerIfNeeded(markerKey, isPausedOrMaxed)
94
- end
95
- --[[
96
- Function to add job considering priority.
97
- ]]
98
- -- Includes
99
- --[[
100
- Function to get priority score.
101
- ]]
102
- local function getPriorityScore(priority, priorityCounterKey)
103
- local prioCounter = rcall("INCR", priorityCounterKey)
104
- return priority * 0x100000000 + prioCounter % 0x100000000
105
- end
106
- local function addJobWithPriority(markerKey, prioritizedKey, priority, jobId, priorityCounterKey,
107
- isPausedOrMaxed)
108
- local score = getPriorityScore(priority, priorityCounterKey)
109
- rcall("ZADD", prioritizedKey, score, jobId)
110
- addBaseMarkerIfNeeded(markerKey, isPausedOrMaxed)
111
- end
112
- --[[
113
- Function to check if queue is paused or maxed
114
- (since an empty list and !EXISTS are not really the same).
115
- ]]
116
- local function isQueuePausedOrMaxed(queueMetaKey, activeKey)
117
- local queueAttributes = rcall("HMGET", queueMetaKey, "paused", "concurrency")
118
- if queueAttributes[1] then
119
- return true
120
- else
121
- if queueAttributes[2] then
122
- local activeCount = rcall("LLEN", activeKey)
123
- return activeCount >= tonumber(queueAttributes[2])
124
- end
125
- end
126
- return false
127
- end
128
- --[[
129
- Function to check for the meta.paused key to decide if we are paused or not
130
- (since an empty list and !EXISTS are not really the same).
131
- ]]
132
- local function getTargetQueueList(queueMetaKey, activeKey, waitKey, pausedKey)
133
- local queueAttributes = rcall("HMGET", queueMetaKey, "paused", "concurrency")
134
- if queueAttributes[1] then
135
- return pausedKey, true
136
- else
137
- if queueAttributes[2] then
138
- local activeCount = rcall("LLEN", activeKey)
139
- if activeCount >= tonumber(queueAttributes[2]) then
140
- return waitKey, true
141
- else
142
- return waitKey, false
143
- end
144
- end
145
- end
146
- return waitKey, 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
- local function removeLock(jobKey, stalledKey, token, jobId)
456
- if token ~= "0" then
457
- local lockKey = jobKey .. ':lock'
458
- local lockToken = rcall("GET", lockKey)
459
- if lockToken == token then
460
- rcall("DEL", lockKey)
461
- rcall("SREM", stalledKey, jobId)
462
- else
463
- if lockToken then
464
- -- Lock exists but token does not match
465
- return -6
466
- else
467
- -- Lock is missing completely
468
- return -2
469
- end
470
- end
471
- end
472
- return 0
473
- end
474
- local function moveToWaitingChildren(activeKey, waitingChildrenKey, jobId,
475
- timestamp)
476
- local score = tonumber(timestamp)
477
- local numRemovedElements = rcall("LREM", activeKey, -1, jobId)
478
- if(numRemovedElements < 1) then
479
- return -3
480
- end
481
- rcall("ZADD", waitingChildrenKey, score, jobId)
482
- return 0
483
- end
484
- if rcall("EXISTS", jobKey) == 1 then
485
- if rcall("ZCARD", jobUnsuccessfulKey) ~= 0 then
486
- -- TODO: refactor this logic in an include later
487
- local jobAttributes = rcall("HMGET", jobKey, "parent", "deid", "opts")
488
- removeDeduplicationKeyIfNeededOnFinalization(ARGV[5], jobAttributes[2], jobId)
489
- local failedReason = "children are failed"
490
- rcall("ZADD", failedKey, timestamp, jobId)
491
- rcall("HSET", jobKey, "finishedOn", timestamp)
492
- rcall("XADD", KEYS[8], "*", "event", "failed", "jobId", jobId, "failedReason",
493
- failedReason, "prev", "active")
494
- local rawParentData = jobAttributes[1]
495
- local rawOpts = jobAttributes[3]
496
- local opts = cjson.decode(rawOpts)
497
- moveChildFromDependenciesIfNeeded(rawParentData, jobKey, failedReason, timestamp)
498
- removeJobsOnFail(ARGV[5], failedKey, jobId, opts, timestamp)
499
- return 0
500
- else
501
- if ARGV[2] ~= "" then
502
- if rcall("SISMEMBER", jobDependenciesKey, ARGV[2]) ~= 0 then
503
- local errorCode = removeLock(jobKey, stalledKey, ARGV[1], jobId)
504
- if errorCode < 0 then
505
- return errorCode
506
- end
507
- return moveToWaitingChildren(activeKey, waitingChildrenKey, jobId, timestamp)
508
- end
509
- return 1
510
- else
511
- if rcall("SCARD", jobDependenciesKey) ~= 0 then
512
- local errorCode = removeLock(jobKey, stalledKey, ARGV[1], jobId)
513
- if errorCode < 0 then
514
- return errorCode
515
- end
516
- return moveToWaitingChildren(activeKey, waitingChildrenKey, jobId, timestamp)
517
- end
518
- return 1
519
- end
520
- end
521
- end
522
- return -1
523
- `;
524
- exports.moveToWaitingChildren = {
525
- name: 'moveToWaitingChildren',
526
- content,
527
- keys: 8,
528
- };
529
- //# sourceMappingURL=moveToWaitingChildren-8.js.map