@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.
- package/dist/externalVersion.js +2 -2
- package/dist/node_modules/bullmq/dist/cjs/classes/queue.js +4 -2
- package/dist/node_modules/bullmq/dist/cjs/classes/scripts.js +3 -3
- package/dist/node_modules/bullmq/dist/cjs/classes/worker.js +8 -9
- package/dist/node_modules/bullmq/dist/cjs/commands/includes/moveJobToWait.lua +15 -0
- package/dist/node_modules/bullmq/dist/cjs/commands/moveJobFromActiveToWait-9.lua +5 -1
- package/dist/node_modules/bullmq/dist/cjs/commands/moveStalledJobsToWait-8.lua +3 -11
- package/dist/node_modules/bullmq/dist/cjs/commands/{moveToWaitingChildren-8.lua → moveToWaitingChildren-7.lua} +29 -40
- package/dist/node_modules/bullmq/dist/cjs/enums/error-code.js +1 -1
- package/dist/node_modules/bullmq/dist/cjs/index.js +1 -1
- package/dist/node_modules/bullmq/dist/cjs/scripts/index.js +1 -1
- package/dist/node_modules/bullmq/dist/cjs/scripts/moveJobFromActiveToWait-9.js +5 -1
- package/dist/node_modules/bullmq/dist/cjs/scripts/moveStalledJobsToWait-8.js +12 -8
- package/dist/node_modules/bullmq/dist/cjs/scripts/moveToWaitingChildren-7.js +107 -0
- package/dist/node_modules/bullmq/dist/cjs/tsconfig-cjs.tsbuildinfo +1 -1
- package/dist/node_modules/bullmq/dist/cjs/version.js +1 -1
- package/dist/node_modules/bullmq/dist/esm/classes/queue.d.ts +1 -1
- package/dist/node_modules/bullmq/dist/esm/classes/queue.js +4 -2
- package/dist/node_modules/bullmq/dist/esm/classes/scripts.js +3 -3
- package/dist/node_modules/bullmq/dist/esm/classes/worker.js +8 -9
- package/dist/node_modules/bullmq/dist/esm/commands/includes/moveJobToWait.lua +15 -0
- package/dist/node_modules/bullmq/dist/esm/commands/moveJobFromActiveToWait-9.lua +5 -1
- package/dist/node_modules/bullmq/dist/esm/commands/moveStalledJobsToWait-8.lua +3 -11
- package/dist/node_modules/bullmq/dist/esm/commands/{moveToWaitingChildren-8.lua → moveToWaitingChildren-7.lua} +29 -40
- package/dist/node_modules/bullmq/dist/esm/enums/error-code.d.ts +1 -1
- package/dist/node_modules/bullmq/dist/esm/enums/error-code.js +1 -1
- package/dist/node_modules/bullmq/dist/esm/scripts/index.d.ts +1 -1
- package/dist/node_modules/bullmq/dist/esm/scripts/index.js +1 -1
- package/dist/node_modules/bullmq/dist/esm/scripts/moveJobFromActiveToWait-9.js +5 -1
- package/dist/node_modules/bullmq/dist/esm/scripts/moveStalledJobsToWait-8.js +12 -8
- package/dist/node_modules/bullmq/dist/esm/scripts/moveToWaitingChildren-7.js +104 -0
- package/dist/node_modules/bullmq/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/dist/node_modules/bullmq/dist/esm/version.d.ts +1 -1
- package/dist/node_modules/bullmq/dist/esm/version.js +1 -1
- package/dist/node_modules/bullmq/package.json +1 -1
- package/dist/node_modules/docxtemplater/package.json +1 -1
- package/dist/node_modules/pizzip/package.json +1 -1
- package/package.json +6 -6
- package/dist/node_modules/bullmq/dist/cjs/scripts/moveToWaitingChildren-8.js +0 -529
- package/dist/node_modules/bullmq/dist/esm/scripts/moveToWaitingChildren-8.js +0 -526
- /package/dist/node_modules/bullmq/dist/esm/scripts/{moveToWaitingChildren-8.d.ts → moveToWaitingChildren-7.d.ts} +0 -0
|
@@ -222,8 +222,7 @@ export class Worker extends QueueBase {
|
|
|
222
222
|
const jobsInProgress = new Set();
|
|
223
223
|
this.startLockExtenderTimer(jobsInProgress);
|
|
224
224
|
let tokenPostfix = 0;
|
|
225
|
-
while (!this.closing && !this.paused) {
|
|
226
|
-
let numTotal = asyncFifoQueue.numTotal();
|
|
225
|
+
while ((!this.closing && !this.paused) || asyncFifoQueue.numTotal() > 0) {
|
|
227
226
|
/**
|
|
228
227
|
* This inner loop tries to fetch jobs concurrently, but if we are waiting for a job
|
|
229
228
|
* to arrive at the queue we should not try to fetch more jobs (as it would be pointless)
|
|
@@ -231,13 +230,12 @@ export class Worker extends QueueBase {
|
|
|
231
230
|
while (!this.closing &&
|
|
232
231
|
!this.paused &&
|
|
233
232
|
!this.waiting &&
|
|
234
|
-
numTotal < this._concurrency &&
|
|
233
|
+
asyncFifoQueue.numTotal() < this._concurrency &&
|
|
235
234
|
!this.isRateLimited()) {
|
|
236
235
|
const token = `${this.id}:${tokenPostfix++}`;
|
|
237
236
|
const fetchedJob = this.retryIfFailed(() => this._getNextJob(client, bclient, token, { block: true }), this.opts.runRetryDelay);
|
|
238
237
|
asyncFifoQueue.add(fetchedJob);
|
|
239
|
-
|
|
240
|
-
if (this.waiting && numTotal > 1) {
|
|
238
|
+
if (this.waiting && asyncFifoQueue.numTotal() > 1) {
|
|
241
239
|
// We are waiting for jobs but we have others that we could start processing already
|
|
242
240
|
break;
|
|
243
241
|
}
|
|
@@ -245,7 +243,7 @@ export class Worker extends QueueBase {
|
|
|
245
243
|
// to Redis in high concurrency scenarios.
|
|
246
244
|
const job = await fetchedJob;
|
|
247
245
|
// No more jobs waiting but we have others that could start processing already
|
|
248
|
-
if (!job && numTotal > 1) {
|
|
246
|
+
if (!job && asyncFifoQueue.numTotal() > 1) {
|
|
249
247
|
break;
|
|
250
248
|
}
|
|
251
249
|
// If there are potential jobs to be processed and blockUntil is set, we should exit to avoid waiting
|
|
@@ -268,7 +266,6 @@ export class Worker extends QueueBase {
|
|
|
268
266
|
await this.waitForRateLimit();
|
|
269
267
|
}
|
|
270
268
|
}
|
|
271
|
-
return asyncFifoQueue.waitAll();
|
|
272
269
|
}
|
|
273
270
|
/**
|
|
274
271
|
* Returns a promise that resolves to the next job in queue.
|
|
@@ -461,7 +458,7 @@ export class Worker extends QueueBase {
|
|
|
461
458
|
// Add next scheduled job if necessary.
|
|
462
459
|
if (job.opts.repeat && !job.nextRepeatableJobId) {
|
|
463
460
|
// Use new job scheduler if possible
|
|
464
|
-
if (job.repeatJobKey) {
|
|
461
|
+
if (job.repeatJobKey && job.repeatJobKey.split(':').length < 5) {
|
|
465
462
|
const jobScheduler = await this.jobScheduler;
|
|
466
463
|
await jobScheduler.upsertJobScheduler(job.repeatJobKey, job.opts.repeat, job.name, job.data, job.opts, { override: false, producerId: job.id });
|
|
467
464
|
}
|
|
@@ -573,7 +570,9 @@ export class Worker extends QueueBase {
|
|
|
573
570
|
});
|
|
574
571
|
if (!this.paused) {
|
|
575
572
|
this.paused = true;
|
|
576
|
-
|
|
573
|
+
if (!doNotWaitActive) {
|
|
574
|
+
await this.whenCurrentJobsFinished();
|
|
575
|
+
}
|
|
577
576
|
(_a = this.stalledCheckStopper) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
578
577
|
this.emit('paused');
|
|
579
578
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
--[[
|
|
2
|
+
Function to move job to wait to be picked up by a waiting worker.
|
|
3
|
+
]]
|
|
4
|
+
|
|
5
|
+
-- Includes
|
|
6
|
+
--- @include "addJobInTargetList"
|
|
7
|
+
--- @include "getTargetQueueList"
|
|
8
|
+
|
|
9
|
+
local function moveJobToWait(metaKey, activeKey, waitKey, pausedKey, markerKey, eventStreamKey,
|
|
10
|
+
jobId, pushCmd)
|
|
11
|
+
local target, isPausedOrMaxed = getTargetQueueList(metaKey, activeKey, waitKey, pausedKey)
|
|
12
|
+
addJobInTargetList(target, markerKey, pushCmd, isPausedOrMaxed, jobId)
|
|
13
|
+
|
|
14
|
+
rcall("XADD", eventStreamKey, "*", "event", "waiting", "jobId", jobId, 'prev', 'active')
|
|
15
|
+
end
|
|
@@ -29,6 +29,10 @@ local jobId = ARGV[1]
|
|
|
29
29
|
local token = ARGV[2]
|
|
30
30
|
local jobKey = ARGV[3]
|
|
31
31
|
|
|
32
|
+
if rcall("EXISTS", jobKey) == 0 then
|
|
33
|
+
return -1
|
|
34
|
+
end
|
|
35
|
+
|
|
32
36
|
local errorCode = removeLock(jobKey, KEYS[3], token, jobId)
|
|
33
37
|
if errorCode < 0 then
|
|
34
38
|
return errorCode
|
|
@@ -60,4 +64,4 @@ if pttl > 0 then
|
|
|
60
64
|
return pttl
|
|
61
65
|
else
|
|
62
66
|
return 0
|
|
63
|
-
end
|
|
67
|
+
end
|
|
@@ -25,6 +25,7 @@ local rcall = redis.call
|
|
|
25
25
|
--- @include "includes/addJobInTargetList"
|
|
26
26
|
--- @include "includes/batches"
|
|
27
27
|
--- @include "includes/getTargetQueueList"
|
|
28
|
+
--- @include "includes/moveJobToWait"
|
|
28
29
|
--- @include "includes/trimEvents"
|
|
29
30
|
|
|
30
31
|
local stalledKey = KEYS[1]
|
|
@@ -73,20 +74,11 @@ if (#stalling > 0) then
|
|
|
73
74
|
-- If this job has been stalled too many times, such as if it crashes the worker, then fail it.
|
|
74
75
|
local stalledCount = rcall("HINCRBY", jobKey, "stc", 1)
|
|
75
76
|
if stalledCount > maxStalledJobCount then
|
|
76
|
-
local jobAttributes = rcall("HMGET", jobKey, "opts", "parent")
|
|
77
|
-
local rawOpts = jobAttributes[1]
|
|
78
|
-
local rawParentData = jobAttributes[2]
|
|
79
|
-
local opts = cjson.decode(rawOpts)
|
|
80
|
-
|
|
81
77
|
local failedReason = "job stalled more than allowable limit"
|
|
82
78
|
rcall("HSET", jobKey, "defa", failedReason)
|
|
83
79
|
end
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
-- Move the job back to the wait queue, to immediately be picked up by a waiting worker.
|
|
87
|
-
addJobInTargetList(target, markerKey, "RPUSH", isPausedOrMaxed, jobId)
|
|
88
|
-
|
|
89
|
-
rcall("XADD", eventStreamKey, "*", "event", "waiting", "jobId", jobId, 'prev', 'active')
|
|
80
|
+
moveJobToWait(metaKey, activeKey, waitKey, pausedKey, markerKey, eventStreamKey, jobId,
|
|
81
|
+
"RPUSH")
|
|
90
82
|
|
|
91
83
|
-- Emit the stalled event
|
|
92
84
|
rcall("XADD", eventStreamKey, "*", "event", "stalled", "jobId", jobId)
|
|
@@ -8,8 +8,7 @@
|
|
|
8
8
|
KEYS[4] job dependencies key
|
|
9
9
|
KEYS[5] job unsuccessful key
|
|
10
10
|
KEYS[6] stalled key
|
|
11
|
-
KEYS[7]
|
|
12
|
-
KEYS[8] events key
|
|
11
|
+
KEYS[7] events key
|
|
13
12
|
|
|
14
13
|
ARGV[1] token
|
|
15
14
|
ARGV[2] child key
|
|
@@ -23,6 +22,7 @@
|
|
|
23
22
|
-1 - Missing job.
|
|
24
23
|
-2 - Missing lock
|
|
25
24
|
-3 - Job not in active set
|
|
25
|
+
-9 - Job has failed children
|
|
26
26
|
]]
|
|
27
27
|
local rcall = redis.call
|
|
28
28
|
local activeKey = KEYS[1]
|
|
@@ -31,71 +31,60 @@ local jobKey = KEYS[3]
|
|
|
31
31
|
local jobDependenciesKey = KEYS[4]
|
|
32
32
|
local jobUnsuccessfulKey = KEYS[5]
|
|
33
33
|
local stalledKey = KEYS[6]
|
|
34
|
-
local
|
|
34
|
+
local eventStreamKey = KEYS[7]
|
|
35
|
+
local token = ARGV[1]
|
|
35
36
|
local timestamp = ARGV[3]
|
|
36
37
|
local jobId = ARGV[4]
|
|
37
38
|
|
|
38
39
|
--- Includes
|
|
39
|
-
--- @include "includes/moveChildFromDependenciesIfNeeded"
|
|
40
|
-
--- @include "includes/removeDeduplicationKeyIfNeededOnFinalization"
|
|
41
|
-
--- @include "includes/removeJobsOnFail"
|
|
42
40
|
--- @include "includes/removeLock"
|
|
43
41
|
|
|
44
|
-
local function
|
|
45
|
-
|
|
46
|
-
local
|
|
42
|
+
local function removeJobFromActive(activeKey, stalledKey, jobKey, jobId,
|
|
43
|
+
token)
|
|
44
|
+
local errorCode = removeLock(jobKey, stalledKey, token, jobId)
|
|
45
|
+
if errorCode < 0 then
|
|
46
|
+
return errorCode
|
|
47
|
+
end
|
|
47
48
|
|
|
48
49
|
local numRemovedElements = rcall("LREM", activeKey, -1, jobId)
|
|
49
50
|
|
|
50
|
-
if
|
|
51
|
+
if numRemovedElements < 1 then
|
|
51
52
|
return -3
|
|
52
53
|
end
|
|
53
54
|
|
|
54
|
-
rcall("ZADD", waitingChildrenKey, score, jobId)
|
|
55
|
-
|
|
56
55
|
return 0
|
|
57
56
|
end
|
|
58
57
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
local failedReason = "children are failed"
|
|
67
|
-
rcall("ZADD", failedKey, timestamp, jobId)
|
|
68
|
-
rcall("HSET", jobKey, "finishedOn", timestamp)
|
|
69
|
-
rcall("XADD", KEYS[8], "*", "event", "failed", "jobId", jobId, "failedReason",
|
|
70
|
-
failedReason, "prev", "active")
|
|
58
|
+
local function moveToWaitingChildren(activeKey, waitingChildrenKey, stalledKey, eventStreamKey,
|
|
59
|
+
jobKey, jobId, timestamp, token)
|
|
60
|
+
local errorCode = removeJobFromActive(activeKey, stalledKey, jobKey, jobId, token)
|
|
61
|
+
if errorCode < 0 then
|
|
62
|
+
return errorCode
|
|
63
|
+
end
|
|
71
64
|
|
|
72
|
-
|
|
73
|
-
local rawOpts = jobAttributes[3]
|
|
74
|
-
local opts = cjson.decode(rawOpts)
|
|
65
|
+
local score = tonumber(timestamp)
|
|
75
66
|
|
|
76
|
-
|
|
67
|
+
rcall("ZADD", waitingChildrenKey, score, jobId)
|
|
68
|
+
rcall("XADD", eventStreamKey, "*", "event", "waiting-children", "jobId", jobId, 'prev', 'active')
|
|
77
69
|
|
|
78
|
-
|
|
70
|
+
return 0
|
|
71
|
+
end
|
|
79
72
|
|
|
80
|
-
|
|
73
|
+
if rcall("EXISTS", jobKey) == 1 then
|
|
74
|
+
if rcall("ZCARD", jobUnsuccessfulKey) ~= 0 then
|
|
75
|
+
return -9
|
|
81
76
|
else
|
|
82
77
|
if ARGV[2] ~= "" then
|
|
83
78
|
if rcall("SISMEMBER", jobDependenciesKey, ARGV[2]) ~= 0 then
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
return errorCode
|
|
87
|
-
end
|
|
88
|
-
return moveToWaitingChildren(activeKey, waitingChildrenKey, jobId, timestamp)
|
|
79
|
+
return moveToWaitingChildren(activeKey, waitingChildrenKey, stalledKey, eventStreamKey,
|
|
80
|
+
jobKey, jobId, timestamp, token)
|
|
89
81
|
end
|
|
90
82
|
|
|
91
83
|
return 1
|
|
92
84
|
else
|
|
93
85
|
if rcall("SCARD", jobDependenciesKey) ~= 0 then
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
return errorCode
|
|
97
|
-
end
|
|
98
|
-
return moveToWaitingChildren(activeKey, waitingChildrenKey, jobId, timestamp)
|
|
86
|
+
return moveToWaitingChildren(activeKey, waitingChildrenKey, stalledKey, eventStreamKey,
|
|
87
|
+
jobKey, jobId, timestamp, token)
|
|
99
88
|
end
|
|
100
89
|
|
|
101
90
|
return 1
|
|
@@ -8,6 +8,6 @@ export var ErrorCode;
|
|
|
8
8
|
ErrorCode[ErrorCode["JobLockMismatch"] = -6] = "JobLockMismatch";
|
|
9
9
|
ErrorCode[ErrorCode["ParentJobCannotBeReplaced"] = -7] = "ParentJobCannotBeReplaced";
|
|
10
10
|
ErrorCode[ErrorCode["JobBelongsToJobScheduler"] = -8] = "JobBelongsToJobScheduler";
|
|
11
|
-
ErrorCode[ErrorCode["
|
|
11
|
+
ErrorCode[ErrorCode["JobHasFailedChildren"] = -9] = "JobHasFailedChildren";
|
|
12
12
|
})(ErrorCode || (ErrorCode = {}));
|
|
13
13
|
//# sourceMappingURL=error-code.js.map
|
|
@@ -28,7 +28,7 @@ export * from './moveStalledJobsToWait-8';
|
|
|
28
28
|
export * from './moveToActive-11';
|
|
29
29
|
export * from './moveToDelayed-8';
|
|
30
30
|
export * from './moveToFinished-14';
|
|
31
|
-
export * from './moveToWaitingChildren-
|
|
31
|
+
export * from './moveToWaitingChildren-7';
|
|
32
32
|
export * from './obliterate-2';
|
|
33
33
|
export * from './paginate-1';
|
|
34
34
|
export * from './pause-7';
|
|
@@ -28,7 +28,7 @@ export * from './moveStalledJobsToWait-8';
|
|
|
28
28
|
export * from './moveToActive-11';
|
|
29
29
|
export * from './moveToDelayed-8';
|
|
30
30
|
export * from './moveToFinished-14';
|
|
31
|
-
export * from './moveToWaitingChildren-
|
|
31
|
+
export * from './moveToWaitingChildren-7';
|
|
32
32
|
export * from './obliterate-2';
|
|
33
33
|
export * from './paginate-1';
|
|
34
34
|
export * from './pause-7';
|
|
@@ -94,6 +94,9 @@ end
|
|
|
94
94
|
local jobId = ARGV[1]
|
|
95
95
|
local token = ARGV[2]
|
|
96
96
|
local jobKey = ARGV[3]
|
|
97
|
+
if rcall("EXISTS", jobKey) == 0 then
|
|
98
|
+
return -1
|
|
99
|
+
end
|
|
97
100
|
local errorCode = removeLock(jobKey, KEYS[3], token, jobId)
|
|
98
101
|
if errorCode < 0 then
|
|
99
102
|
return errorCode
|
|
@@ -118,7 +121,8 @@ if pttl > 0 then
|
|
|
118
121
|
return pttl
|
|
119
122
|
else
|
|
120
123
|
return 0
|
|
121
|
-
end
|
|
124
|
+
end
|
|
125
|
+
`;
|
|
122
126
|
export const moveJobFromActiveToWait = {
|
|
123
127
|
name: 'moveJobFromActiveToWait',
|
|
124
128
|
content,
|
|
@@ -70,6 +70,16 @@ local function getTargetQueueList(queueMetaKey, activeKey, waitKey, pausedKey)
|
|
|
70
70
|
end
|
|
71
71
|
return waitKey, false
|
|
72
72
|
end
|
|
73
|
+
--[[
|
|
74
|
+
Function to move job to wait to be picked up by a waiting worker.
|
|
75
|
+
]]
|
|
76
|
+
-- Includes
|
|
77
|
+
local function moveJobToWait(metaKey, activeKey, waitKey, pausedKey, markerKey, eventStreamKey,
|
|
78
|
+
jobId, pushCmd)
|
|
79
|
+
local target, isPausedOrMaxed = getTargetQueueList(metaKey, activeKey, waitKey, pausedKey)
|
|
80
|
+
addJobInTargetList(target, markerKey, pushCmd, isPausedOrMaxed, jobId)
|
|
81
|
+
rcall("XADD", eventStreamKey, "*", "event", "waiting", "jobId", jobId, 'prev', 'active')
|
|
82
|
+
end
|
|
73
83
|
--[[
|
|
74
84
|
Function to trim events, default 10000.
|
|
75
85
|
]]
|
|
@@ -132,17 +142,11 @@ if (#stalling > 0) then
|
|
|
132
142
|
-- If this job has been stalled too many times, such as if it crashes the worker, then fail it.
|
|
133
143
|
local stalledCount = rcall("HINCRBY", jobKey, "stc", 1)
|
|
134
144
|
if stalledCount > maxStalledJobCount then
|
|
135
|
-
local jobAttributes = rcall("HMGET", jobKey, "opts", "parent")
|
|
136
|
-
local rawOpts = jobAttributes[1]
|
|
137
|
-
local rawParentData = jobAttributes[2]
|
|
138
|
-
local opts = cjson.decode(rawOpts)
|
|
139
145
|
local failedReason = "job stalled more than allowable limit"
|
|
140
146
|
rcall("HSET", jobKey, "defa", failedReason)
|
|
141
147
|
end
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
addJobInTargetList(target, markerKey, "RPUSH", isPausedOrMaxed, jobId)
|
|
145
|
-
rcall("XADD", eventStreamKey, "*", "event", "waiting", "jobId", jobId, 'prev', 'active')
|
|
148
|
+
moveJobToWait(metaKey, activeKey, waitKey, pausedKey, markerKey, eventStreamKey, jobId,
|
|
149
|
+
"RPUSH")
|
|
146
150
|
-- Emit the stalled event
|
|
147
151
|
rcall("XADD", eventStreamKey, "*", "event", "stalled", "jobId", jobId)
|
|
148
152
|
table.insert(stalled, jobId)
|
|
@@ -0,0 +1,104 @@
|
|
|
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] events key
|
|
11
|
+
ARGV[1] token
|
|
12
|
+
ARGV[2] child key
|
|
13
|
+
ARGV[3] timestamp
|
|
14
|
+
ARGV[4] jobId
|
|
15
|
+
ARGV[5] prefix
|
|
16
|
+
Output:
|
|
17
|
+
0 - OK
|
|
18
|
+
1 - There are not pending dependencies.
|
|
19
|
+
-1 - Missing job.
|
|
20
|
+
-2 - Missing lock
|
|
21
|
+
-3 - Job not in active set
|
|
22
|
+
-9 - Job has failed children
|
|
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 eventStreamKey = KEYS[7]
|
|
32
|
+
local token = ARGV[1]
|
|
33
|
+
local timestamp = ARGV[3]
|
|
34
|
+
local jobId = ARGV[4]
|
|
35
|
+
--- Includes
|
|
36
|
+
local function removeLock(jobKey, stalledKey, token, jobId)
|
|
37
|
+
if token ~= "0" then
|
|
38
|
+
local lockKey = jobKey .. ':lock'
|
|
39
|
+
local lockToken = rcall("GET", lockKey)
|
|
40
|
+
if lockToken == token then
|
|
41
|
+
rcall("DEL", lockKey)
|
|
42
|
+
rcall("SREM", stalledKey, jobId)
|
|
43
|
+
else
|
|
44
|
+
if lockToken then
|
|
45
|
+
-- Lock exists but token does not match
|
|
46
|
+
return -6
|
|
47
|
+
else
|
|
48
|
+
-- Lock is missing completely
|
|
49
|
+
return -2
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
return 0
|
|
54
|
+
end
|
|
55
|
+
local function removeJobFromActive(activeKey, stalledKey, jobKey, jobId,
|
|
56
|
+
token)
|
|
57
|
+
local errorCode = removeLock(jobKey, stalledKey, token, jobId)
|
|
58
|
+
if errorCode < 0 then
|
|
59
|
+
return errorCode
|
|
60
|
+
end
|
|
61
|
+
local numRemovedElements = rcall("LREM", activeKey, -1, jobId)
|
|
62
|
+
if numRemovedElements < 1 then
|
|
63
|
+
return -3
|
|
64
|
+
end
|
|
65
|
+
return 0
|
|
66
|
+
end
|
|
67
|
+
local function moveToWaitingChildren(activeKey, waitingChildrenKey, stalledKey, eventStreamKey,
|
|
68
|
+
jobKey, jobId, timestamp, token)
|
|
69
|
+
local errorCode = removeJobFromActive(activeKey, stalledKey, jobKey, jobId, token)
|
|
70
|
+
if errorCode < 0 then
|
|
71
|
+
return errorCode
|
|
72
|
+
end
|
|
73
|
+
local score = tonumber(timestamp)
|
|
74
|
+
rcall("ZADD", waitingChildrenKey, score, jobId)
|
|
75
|
+
rcall("XADD", eventStreamKey, "*", "event", "waiting-children", "jobId", jobId, 'prev', 'active')
|
|
76
|
+
return 0
|
|
77
|
+
end
|
|
78
|
+
if rcall("EXISTS", jobKey) == 1 then
|
|
79
|
+
if rcall("ZCARD", jobUnsuccessfulKey) ~= 0 then
|
|
80
|
+
return -9
|
|
81
|
+
else
|
|
82
|
+
if ARGV[2] ~= "" then
|
|
83
|
+
if rcall("SISMEMBER", jobDependenciesKey, ARGV[2]) ~= 0 then
|
|
84
|
+
return moveToWaitingChildren(activeKey, waitingChildrenKey, stalledKey, eventStreamKey,
|
|
85
|
+
jobKey, jobId, timestamp, token)
|
|
86
|
+
end
|
|
87
|
+
return 1
|
|
88
|
+
else
|
|
89
|
+
if rcall("SCARD", jobDependenciesKey) ~= 0 then
|
|
90
|
+
return moveToWaitingChildren(activeKey, waitingChildrenKey, stalledKey, eventStreamKey,
|
|
91
|
+
jobKey, jobId, timestamp, token)
|
|
92
|
+
end
|
|
93
|
+
return 1
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
return -1
|
|
98
|
+
`;
|
|
99
|
+
export const moveToWaitingChildren = {
|
|
100
|
+
name: 'moveToWaitingChildren',
|
|
101
|
+
content,
|
|
102
|
+
keys: 7,
|
|
103
|
+
};
|
|
104
|
+
//# sourceMappingURL=moveToWaitingChildren-7.js.map
|