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