bullmq 5.1.2 → 5.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/classes/scripts.js +3 -1
- package/dist/cjs/classes/scripts.js.map +1 -1
- package/dist/cjs/commands/addStandardJob-7.lua +4 -8
- package/dist/cjs/commands/changeDelay-3.lua +1 -0
- package/dist/cjs/commands/changePriority-6.lua +0 -1
- package/dist/cjs/commands/includes/addBaseMarkerIfNeeded.lua +9 -0
- package/dist/cjs/commands/includes/addDelayMarkerIfNeeded.lua +3 -1
- package/dist/cjs/commands/includes/addJobInTargetList.lua +11 -0
- package/dist/cjs/commands/includes/addJobWithPriority.lua +5 -3
- package/dist/cjs/commands/includes/moveParentToWaitIfNeeded.lua +6 -4
- package/dist/cjs/commands/includes/promoteDelayedJobs.lua +2 -4
- package/dist/{esm/commands/moveJobsToWait-6.lua → cjs/commands/moveJobsToWait-7.lua} +5 -1
- package/dist/cjs/commands/moveStalledJobsToWait-9.lua +150 -0
- package/dist/cjs/commands/moveToFinished-14.lua +1 -0
- package/dist/cjs/commands/pause-7.lua +1 -0
- package/dist/cjs/commands/promote-8.lua +2 -2
- package/dist/cjs/commands/retryJob-10.lua +1 -0
- package/dist/cjs/scripts/addDelayedJob-6.js +21 -7
- package/dist/cjs/scripts/addDelayedJob-6.js.map +1 -1
- package/dist/cjs/scripts/addParentJob-4.js +25 -11
- package/dist/cjs/scripts/addParentJob-4.js.map +1 -1
- package/dist/cjs/scripts/addPrioritizedJob-7.js +21 -7
- package/dist/cjs/scripts/addPrioritizedJob-7.js.map +1 -1
- package/dist/cjs/scripts/addStandardJob-7.js +46 -36
- package/dist/cjs/scripts/addStandardJob-7.js.map +1 -1
- package/dist/cjs/scripts/changeDelay-3.js +1 -0
- package/dist/cjs/scripts/changeDelay-3.js.map +1 -1
- package/dist/cjs/scripts/changePriority-6.js +10 -14
- package/dist/cjs/scripts/changePriority-6.js.map +1 -1
- package/dist/cjs/scripts/index.js +2 -2
- package/dist/cjs/scripts/{moveJobsToWait-6.js → moveJobsToWait-7.js} +13 -3
- package/dist/cjs/scripts/moveJobsToWait-7.js.map +1 -0
- package/dist/cjs/scripts/{moveStalledJobsToWait-8.js → moveStalledJobsToWait-9.js} +109 -106
- package/dist/cjs/scripts/{moveStalledJobsToWait-8.js.map → moveStalledJobsToWait-9.js.map} +1 -1
- package/dist/cjs/scripts/moveToActive-11.js +19 -7
- package/dist/cjs/scripts/moveToActive-11.js.map +1 -1
- package/dist/cjs/scripts/moveToDelayed-7.js +1 -1
- package/dist/cjs/scripts/moveToFinished-14.js +32 -21
- package/dist/cjs/scripts/moveToFinished-14.js.map +1 -1
- package/dist/cjs/scripts/pause-7.js +2 -1
- package/dist/cjs/scripts/pause-7.js.map +1 -1
- package/dist/cjs/scripts/promote-8.js +19 -5
- package/dist/cjs/scripts/promote-8.js.map +1 -1
- package/dist/cjs/scripts/retryJob-10.js +20 -7
- package/dist/cjs/scripts/retryJob-10.js.map +1 -1
- package/dist/cjs/tsconfig-cjs.tsbuildinfo +1 -1
- package/dist/esm/classes/scripts.js +3 -1
- package/dist/esm/classes/scripts.js.map +1 -1
- package/dist/esm/commands/addStandardJob-7.lua +4 -8
- package/dist/esm/commands/changeDelay-3.lua +1 -0
- package/dist/esm/commands/changePriority-6.lua +0 -1
- package/dist/esm/commands/includes/addBaseMarkerIfNeeded.lua +9 -0
- package/dist/esm/commands/includes/addDelayMarkerIfNeeded.lua +3 -1
- package/dist/esm/commands/includes/addJobInTargetList.lua +11 -0
- package/dist/esm/commands/includes/addJobWithPriority.lua +5 -3
- package/dist/esm/commands/includes/moveParentToWaitIfNeeded.lua +6 -4
- package/dist/esm/commands/includes/promoteDelayedJobs.lua +2 -4
- package/dist/{cjs/commands/moveJobsToWait-6.lua → esm/commands/moveJobsToWait-7.lua} +5 -1
- package/dist/esm/commands/moveStalledJobsToWait-9.lua +150 -0
- package/dist/esm/commands/moveToFinished-14.lua +1 -0
- package/dist/esm/commands/pause-7.lua +1 -0
- package/dist/esm/commands/promote-8.lua +2 -2
- package/dist/esm/commands/retryJob-10.lua +1 -0
- package/dist/esm/scripts/addDelayedJob-6.js +21 -7
- package/dist/esm/scripts/addDelayedJob-6.js.map +1 -1
- package/dist/esm/scripts/addParentJob-4.js +25 -11
- package/dist/esm/scripts/addParentJob-4.js.map +1 -1
- package/dist/esm/scripts/addPrioritizedJob-7.js +21 -7
- package/dist/esm/scripts/addPrioritizedJob-7.js.map +1 -1
- package/dist/esm/scripts/addStandardJob-7.js +46 -36
- package/dist/esm/scripts/addStandardJob-7.js.map +1 -1
- package/dist/esm/scripts/changeDelay-3.js +1 -0
- package/dist/esm/scripts/changeDelay-3.js.map +1 -1
- package/dist/esm/scripts/changePriority-6.js +10 -14
- package/dist/esm/scripts/changePriority-6.js.map +1 -1
- package/dist/esm/scripts/index.d.ts +2 -2
- package/dist/esm/scripts/index.js +2 -2
- package/dist/esm/scripts/{moveJobsToWait-6.js → moveJobsToWait-7.js} +13 -3
- package/dist/esm/scripts/moveJobsToWait-7.js.map +1 -0
- package/dist/esm/scripts/{moveStalledJobsToWait-8.js → moveStalledJobsToWait-9.js} +109 -106
- package/dist/esm/scripts/{moveStalledJobsToWait-8.js.map → moveStalledJobsToWait-9.js.map} +1 -1
- package/dist/esm/scripts/moveToActive-11.js +19 -7
- package/dist/esm/scripts/moveToActive-11.js.map +1 -1
- package/dist/esm/scripts/moveToDelayed-7.js +1 -1
- package/dist/esm/scripts/moveToFinished-14.js +32 -21
- package/dist/esm/scripts/moveToFinished-14.js.map +1 -1
- package/dist/esm/scripts/pause-7.js +2 -1
- package/dist/esm/scripts/pause-7.js.map +1 -1
- package/dist/esm/scripts/promote-8.js +19 -5
- package/dist/esm/scripts/promote-8.js.map +1 -1
- package/dist/esm/scripts/retryJob-10.js +20 -7
- package/dist/esm/scripts/retryJob-10.js.map +1 -1
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/dist/cjs/commands/includes/checkStalledJobs.lua +0 -139
- package/dist/cjs/commands/moveStalledJobsToWait-8.lua +0 -24
- package/dist/cjs/scripts/moveJobsToWait-6.js.map +0 -1
- package/dist/esm/commands/includes/checkStalledJobs.lua +0 -139
- package/dist/esm/commands/moveStalledJobsToWait-8.lua +0 -24
- package/dist/esm/scripts/moveJobsToWait-6.js.map +0 -1
- /package/dist/esm/scripts/{moveJobsToWait-6.d.ts → moveJobsToWait-7.d.ts} +0 -0
- /package/dist/esm/scripts/{moveStalledJobsToWait-8.d.ts → moveStalledJobsToWait-9.d.ts} +0 -0
@@ -7,6 +7,7 @@
|
|
7
7
|
]]
|
8
8
|
|
9
9
|
-- Includes
|
10
|
+
--- @include "addJobInTargetList"
|
10
11
|
--- @include "addJobWithPriority"
|
11
12
|
|
12
13
|
-- Try to get as much as 1000 jobs at once
|
@@ -24,10 +25,7 @@ local function promoteDelayedJobs(delayedKey, markerKey, targetKey, prioritizedK
|
|
24
25
|
|
25
26
|
if priority == 0 then
|
26
27
|
-- LIFO or FIFO
|
27
|
-
|
28
|
-
if not isPaused then
|
29
|
-
rcall("ZADD", markerKey, 0, "0")
|
30
|
-
end
|
28
|
+
addJobInTargetList(targetKey, markerKey, "LPUSH", isPaused, jobId)
|
31
29
|
else
|
32
30
|
addJobWithPriority(markerKey, prioritizedKey, priority,
|
33
31
|
jobId, priorityCounterKey, isPaused)
|
@@ -10,6 +10,7 @@
|
|
10
10
|
KEYS[4] 'wait'
|
11
11
|
KEYS[5] 'paused'
|
12
12
|
KEYS[6] 'meta'
|
13
|
+
KEYS[7] 'marker'
|
13
14
|
|
14
15
|
ARGV[1] count
|
15
16
|
ARGV[2] timestamp
|
@@ -25,12 +26,13 @@ local timestamp = tonumber(ARGV[2])
|
|
25
26
|
local rcall = redis.call;
|
26
27
|
|
27
28
|
-- Includes
|
29
|
+
--- @include "includes/addBaseMarkerIfNeeded"
|
28
30
|
--- @include "includes/batches"
|
29
31
|
--- @include "includes/getOrSetMaxEvents"
|
30
32
|
--- @include "includes/getTargetQueueList"
|
31
33
|
|
32
34
|
local metaKey = KEYS[6]
|
33
|
-
local target = getTargetQueueList(metaKey, KEYS[4], KEYS[5])
|
35
|
+
local target, paused = getTargetQueueList(metaKey, KEYS[4], KEYS[5])
|
34
36
|
|
35
37
|
local jobs = rcall('ZRANGEBYSCORE', KEYS[3], 0, timestamp, 'LIMIT', 0, maxCount)
|
36
38
|
if (#jobs > 0) then
|
@@ -59,6 +61,8 @@ if (#jobs > 0) then
|
|
59
61
|
rcall("ZREM", KEYS[3], unpack(jobs, from, to))
|
60
62
|
rcall("LPUSH", target, unpack(jobs, from, to))
|
61
63
|
end
|
64
|
+
|
65
|
+
addBaseMarkerIfNeeded(KEYS[7], paused)
|
62
66
|
end
|
63
67
|
|
64
68
|
maxCount = maxCount - #jobs
|
@@ -0,0 +1,150 @@
|
|
1
|
+
--[[
|
2
|
+
Move stalled jobs to wait.
|
3
|
+
|
4
|
+
Input:
|
5
|
+
KEYS[1] 'stalled' (SET)
|
6
|
+
KEYS[2] 'wait', (LIST)
|
7
|
+
KEYS[3] 'active', (LIST)
|
8
|
+
KEYS[4] 'failed', (ZSET)
|
9
|
+
KEYS[5] 'stalled-check', (KEY)
|
10
|
+
KEYS[6] 'meta', (KEY)
|
11
|
+
KEYS[7] 'paused', (LIST)
|
12
|
+
KEYS[8] 'marker'
|
13
|
+
KEYS[9] 'event stream' (STREAM)
|
14
|
+
|
15
|
+
ARGV[1] Max stalled job count
|
16
|
+
ARGV[2] queue.toKey('')
|
17
|
+
ARGV[3] timestamp
|
18
|
+
ARGV[4] max check time
|
19
|
+
|
20
|
+
Events:
|
21
|
+
'stalled' with stalled job id.
|
22
|
+
]]
|
23
|
+
|
24
|
+
local rcall = redis.call
|
25
|
+
|
26
|
+
-- Includes
|
27
|
+
--- @include "includes/addJobInTargetList"
|
28
|
+
--- @include "includes/batches"
|
29
|
+
--- @include "includes/getTargetQueueList"
|
30
|
+
--- @include "includes/removeJob"
|
31
|
+
--- @include "includes/removeJobsByMaxAge"
|
32
|
+
--- @include "includes/removeJobsByMaxCount"
|
33
|
+
--- @include "includes/trimEvents"
|
34
|
+
|
35
|
+
local stalledKey = KEYS[1]
|
36
|
+
local waitKey = KEYS[2]
|
37
|
+
local activeKey = KEYS[3]
|
38
|
+
local failedKey = KEYS[4]
|
39
|
+
local stalledCheckKey = KEYS[5]
|
40
|
+
local metaKey = KEYS[6]
|
41
|
+
local pausedKey = KEYS[7]
|
42
|
+
local markerKey = KEYS[8]
|
43
|
+
local eventStreamKey = KEYS[9]
|
44
|
+
local maxStalledJobCount = ARGV[1]
|
45
|
+
local queueKeyPrefix = ARGV[2]
|
46
|
+
local timestamp = ARGV[3]
|
47
|
+
local maxCheckTime = ARGV[4]
|
48
|
+
|
49
|
+
if rcall("EXISTS", stalledCheckKey) == 1 then return {{}, {}} end
|
50
|
+
|
51
|
+
rcall("SET", stalledCheckKey, timestamp, "PX", maxCheckTime)
|
52
|
+
|
53
|
+
-- Trim events before emiting them to avoid trimming events emitted in this script
|
54
|
+
trimEvents(metaKey, eventStreamKey)
|
55
|
+
|
56
|
+
-- Move all stalled jobs to wait
|
57
|
+
local stalling = rcall('SMEMBERS', stalledKey)
|
58
|
+
local stalled = {}
|
59
|
+
local failed = {}
|
60
|
+
if (#stalling > 0) then
|
61
|
+
rcall('DEL', stalledKey)
|
62
|
+
|
63
|
+
local MAX_STALLED_JOB_COUNT = tonumber(maxStalledJobCount)
|
64
|
+
|
65
|
+
-- Remove from active list
|
66
|
+
for i, jobId in ipairs(stalling) do
|
67
|
+
-- Markers in waitlist DEPRECATED in v5: Remove in v6.
|
68
|
+
if string.sub(jobId, 1, 2) == "0:" then
|
69
|
+
-- If the jobId is a delay marker ID we just remove it.
|
70
|
+
rcall("LREM", activeKey, 1, jobId)
|
71
|
+
else
|
72
|
+
local jobKey = queueKeyPrefix .. jobId
|
73
|
+
|
74
|
+
-- Check that the lock is also missing, then we can handle this job as really stalled.
|
75
|
+
if (rcall("EXISTS", jobKey .. ":lock") == 0) then
|
76
|
+
-- Remove from the active queue.
|
77
|
+
local removed = rcall("LREM", activeKey, 1, jobId)
|
78
|
+
|
79
|
+
if (removed > 0) then
|
80
|
+
-- If this job has been stalled too many times, such as if it crashes the worker, then fail it.
|
81
|
+
local stalledCount =
|
82
|
+
rcall("HINCRBY", jobKey, "stalledCounter", 1)
|
83
|
+
if (stalledCount > MAX_STALLED_JOB_COUNT) then
|
84
|
+
local rawOpts = rcall("HGET", jobKey, "opts")
|
85
|
+
local opts = cjson.decode(rawOpts)
|
86
|
+
local removeOnFailType = type(opts["removeOnFail"])
|
87
|
+
rcall("ZADD", failedKey, timestamp, jobId)
|
88
|
+
local failedReason =
|
89
|
+
"job stalled more than allowable limit"
|
90
|
+
rcall("HMSET", jobKey, "failedReason", failedReason,
|
91
|
+
"finishedOn", timestamp)
|
92
|
+
rcall("XADD", eventStreamKey, "*", "event",
|
93
|
+
"failed", "jobId", jobId, 'prev', 'active',
|
94
|
+
'failedReason', failedReason)
|
95
|
+
|
96
|
+
if removeOnFailType == "number" then
|
97
|
+
removeJobsByMaxCount(opts["removeOnFail"],
|
98
|
+
failedKey, queueKeyPrefix)
|
99
|
+
elseif removeOnFailType == "boolean" then
|
100
|
+
if opts["removeOnFail"] then
|
101
|
+
removeJob(jobId, false, queueKeyPrefix)
|
102
|
+
rcall("ZREM", failedKey, jobId)
|
103
|
+
end
|
104
|
+
elseif removeOnFailType ~= "nil" then
|
105
|
+
local maxAge = opts["removeOnFail"]["age"]
|
106
|
+
local maxCount = opts["removeOnFail"]["count"]
|
107
|
+
|
108
|
+
if maxAge ~= nil then
|
109
|
+
removeJobsByMaxAge(timestamp, maxAge,
|
110
|
+
failedKey, queueKeyPrefix)
|
111
|
+
end
|
112
|
+
|
113
|
+
if maxCount ~= nil and maxCount > 0 then
|
114
|
+
removeJobsByMaxCount(maxCount, failedKey,
|
115
|
+
queueKeyPrefix)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
table.insert(failed, jobId)
|
120
|
+
else
|
121
|
+
local target, isPaused=
|
122
|
+
getTargetQueueList(metaKey, waitKey, pausedKey)
|
123
|
+
|
124
|
+
-- Move the job back to the wait queue, to immediately be picked up by a waiting worker.
|
125
|
+
addJobInTargetList(target, markerKey, "RPUSH", isPaused, jobId)
|
126
|
+
|
127
|
+
rcall("XADD", eventStreamKey, "*", "event",
|
128
|
+
"waiting", "jobId", jobId, 'prev', 'active')
|
129
|
+
|
130
|
+
-- Emit the stalled event
|
131
|
+
rcall("XADD", eventStreamKey, "*", "event",
|
132
|
+
"stalled", "jobId", jobId)
|
133
|
+
table.insert(stalled, jobId)
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
-- Mark potentially stalled jobs
|
142
|
+
local active = rcall('LRANGE', activeKey, 0, -1)
|
143
|
+
|
144
|
+
if (#active > 0) then
|
145
|
+
for from, to in batches(#active, 7000) do
|
146
|
+
rcall('SADD', stalledKey, unpack(active, from, to))
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
return {failed, stalled}
|
@@ -57,6 +57,7 @@ local rcall = redis.call
|
|
57
57
|
--- Includes
|
58
58
|
--- @include "includes/collectMetrics"
|
59
59
|
--- @include "includes/getNextDelayedTimestamp"
|
60
|
+
--- @include "includes/getTargetQueueList"
|
60
61
|
--- @include "includes/moveJobFromPriorityToActive"
|
61
62
|
--- @include "includes/prepareJobForProcessing"
|
62
63
|
--- @include "includes/moveParentFromWaitingChildrenToFailed"
|
@@ -25,6 +25,7 @@ local rcall = redis.call
|
|
25
25
|
local jobId = ARGV[2]
|
26
26
|
|
27
27
|
-- Includes
|
28
|
+
--- @include "includes/addJobInTargetList"
|
28
29
|
--- @include "includes/addJobWithPriority"
|
29
30
|
--- @include "includes/getTargetQueueList"
|
30
31
|
|
@@ -42,8 +43,7 @@ if rcall("ZREM", KEYS[1], jobId) == 1 then
|
|
42
43
|
|
43
44
|
if priority == 0 then
|
44
45
|
-- LIFO or FIFO
|
45
|
-
|
46
|
-
if not paused then rcall("ZADD", KEYS[8], 0, "0") end
|
46
|
+
addJobInTargetList(target, KEYS[8], "LPUSH", paused, jobId)
|
47
47
|
else
|
48
48
|
addJobWithPriority(KEYS[8], KEYS[5], priority, jobId, KEYS[6], paused)
|
49
49
|
end
|
@@ -60,6 +60,7 @@ if rcall("EXISTS", KEYS[4]) == 1 then
|
|
60
60
|
-- Standard or priority add
|
61
61
|
if priority == 0 then
|
62
62
|
rcall(ARGV[3], target, ARGV[4])
|
63
|
+
-- TODO: check if we need to add marker in this case too
|
63
64
|
else
|
64
65
|
addJobWithPriority(markerKey, KEYS[8], priority, ARGV[4], KEYS[9], paused)
|
65
66
|
end
|
@@ -46,7 +46,7 @@ local parentData
|
|
46
46
|
-- Includes
|
47
47
|
--[[
|
48
48
|
Add delay marker if needed.
|
49
|
-
]]
|
49
|
+
]]
|
50
50
|
-- Includes
|
51
51
|
--[[
|
52
52
|
Function to return the next delayed job timestamp.
|
@@ -127,16 +127,31 @@ end
|
|
127
127
|
Validate and move parent to active if needed.
|
128
128
|
]]
|
129
129
|
-- Includes
|
130
|
+
--[[
|
131
|
+
Function to add job in target list and add marker if needed.
|
132
|
+
]]
|
133
|
+
-- Includes
|
134
|
+
--[[
|
135
|
+
Add marker if needed when a job is available.
|
136
|
+
]]
|
137
|
+
local function addBaseMarkerIfNeeded(markerKey, isPaused)
|
138
|
+
if not isPaused then
|
139
|
+
rcall("ZADD", markerKey, 0, "0")
|
140
|
+
end
|
141
|
+
end
|
142
|
+
local function addJobInTargetList(targetKey, markerKey, pushCmd, isPaused, jobId)
|
143
|
+
rcall(pushCmd, targetKey, jobId)
|
144
|
+
addBaseMarkerIfNeeded(markerKey, isPaused)
|
145
|
+
end
|
130
146
|
--[[
|
131
147
|
Function to add job considering priority.
|
132
148
|
]]
|
149
|
+
-- Includes
|
133
150
|
local function addJobWithPriority(markerKey, prioritizedKey, priority, jobId, priorityCounterKey, isPaused)
|
134
151
|
local prioCounter = rcall("INCR", priorityCounterKey)
|
135
152
|
local score = priority * 0x100000000 + bit.band(prioCounter, 0xffffffffffff)
|
136
153
|
rcall("ZADD", prioritizedKey, score, jobId)
|
137
|
-
|
138
|
-
rcall("ZADD", markerKey, 0, "0")
|
139
|
-
end
|
154
|
+
addBaseMarkerIfNeeded(markerKey, isPaused)
|
140
155
|
end
|
141
156
|
--[[
|
142
157
|
Function to check for the meta.paused key to decide if we are paused or not
|
@@ -172,11 +187,10 @@ local function moveParentToWaitIfNeeded(parentQueueKey, parentDependenciesKey,
|
|
172
187
|
addDelayMarkerIfNeeded(parentMarkerKey, parentDelayedKey)
|
173
188
|
else
|
174
189
|
if priority == 0 then
|
175
|
-
local parentTarget,
|
190
|
+
local parentTarget, isParentPaused =
|
176
191
|
getTargetQueueList(parentMetaKey, parentWaitKey,
|
177
192
|
parentPausedKey)
|
178
|
-
|
179
|
-
rcall("ZADD", parentMarkerKey, 0, "0")
|
193
|
+
addJobInTargetList(parentTarget, parentMarkerKey, "RPUSH", isParentPaused, parentId)
|
180
194
|
else
|
181
195
|
local isPaused = isQueuePaused(parentMetaKey)
|
182
196
|
addJobWithPriority(parentMarkerKey,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"addDelayedJob-6.js","sourceRoot":"","sources":["../../../src/scripts/addDelayedJob-6.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG
|
1
|
+
{"version":3,"file":"addDelayedJob-6.js","sourceRoot":"","sources":["../../../src/scripts/addDelayedJob-6.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgRf,CAAC;AACF,MAAM,CAAC,MAAM,aAAa,GAAG;IAC3B,IAAI,EAAE,eAAe;IACrB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
|
@@ -81,7 +81,7 @@ end
|
|
81
81
|
-- Includes
|
82
82
|
--[[
|
83
83
|
Add delay marker if needed.
|
84
|
-
]]
|
84
|
+
]]
|
85
85
|
-- Includes
|
86
86
|
--[[
|
87
87
|
Function to return the next delayed job timestamp.
|
@@ -105,22 +105,37 @@ local function addDelayMarkerIfNeeded(markerKey, delayedKey)
|
|
105
105
|
end
|
106
106
|
end
|
107
107
|
--[[
|
108
|
-
Function to
|
109
|
-
(since an empty list and !EXISTS are not really the same).
|
108
|
+
Function to add job in target list and add marker if needed.
|
110
109
|
]]
|
111
|
-
|
112
|
-
|
110
|
+
-- Includes
|
111
|
+
--[[
|
112
|
+
Add marker if needed when a job is available.
|
113
|
+
]]
|
114
|
+
local function addBaseMarkerIfNeeded(markerKey, isPaused)
|
115
|
+
if not isPaused then
|
116
|
+
rcall("ZADD", markerKey, 0, "0")
|
117
|
+
end
|
118
|
+
end
|
119
|
+
local function addJobInTargetList(targetKey, markerKey, pushCmd, isPaused, jobId)
|
120
|
+
rcall(pushCmd, targetKey, jobId)
|
121
|
+
addBaseMarkerIfNeeded(markerKey, isPaused)
|
113
122
|
end
|
114
123
|
--[[
|
115
124
|
Function to add job considering priority.
|
116
125
|
]]
|
126
|
+
-- Includes
|
117
127
|
local function addJobWithPriority(markerKey, prioritizedKey, priority, jobId, priorityCounterKey, isPaused)
|
118
128
|
local prioCounter = rcall("INCR", priorityCounterKey)
|
119
129
|
local score = priority * 0x100000000 + bit.band(prioCounter, 0xffffffffffff)
|
120
130
|
rcall("ZADD", prioritizedKey, score, jobId)
|
121
|
-
|
122
|
-
|
123
|
-
|
131
|
+
addBaseMarkerIfNeeded(markerKey, isPaused)
|
132
|
+
end
|
133
|
+
--[[
|
134
|
+
Function to check for the meta.paused key to decide if we are paused or not
|
135
|
+
(since an empty list and !EXISTS are not really the same).
|
136
|
+
]]
|
137
|
+
local function isQueuePaused(queueMetaKey)
|
138
|
+
return rcall("HEXISTS", queueMetaKey, "paused") == 1
|
124
139
|
end
|
125
140
|
--[[
|
126
141
|
Function to check for the meta.paused key to decide if we are paused or not
|
@@ -156,11 +171,10 @@ local function moveParentToWaitIfNeeded(parentQueueKey, parentDependenciesKey,
|
|
156
171
|
addDelayMarkerIfNeeded(parentMarkerKey, parentDelayedKey)
|
157
172
|
else
|
158
173
|
if priority == 0 then
|
159
|
-
local parentTarget,
|
174
|
+
local parentTarget, isParentPaused =
|
160
175
|
getTargetQueueList(parentMetaKey, parentWaitKey,
|
161
176
|
parentPausedKey)
|
162
|
-
|
163
|
-
rcall("ZADD", parentMarkerKey, 0, "0")
|
177
|
+
addJobInTargetList(parentTarget, parentMarkerKey, "RPUSH", isParentPaused, parentId)
|
164
178
|
else
|
165
179
|
local isPaused = isQueuePaused(parentMetaKey)
|
166
180
|
addJobWithPriority(parentMarkerKey,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"addParentJob-4.js","sourceRoot":"","sources":["../../../src/scripts/addParentJob-4.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG
|
1
|
+
{"version":3,"file":"addParentJob-4.js","sourceRoot":"","sources":["../../../src/scripts/addParentJob-4.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiQf,CAAC;AACF,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,IAAI,EAAE,cAAc;IACpB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
|
@@ -79,13 +79,20 @@ end
|
|
79
79
|
--[[
|
80
80
|
Function to add job considering priority.
|
81
81
|
]]
|
82
|
+
-- Includes
|
83
|
+
--[[
|
84
|
+
Add marker if needed when a job is available.
|
85
|
+
]]
|
86
|
+
local function addBaseMarkerIfNeeded(markerKey, isPaused)
|
87
|
+
if not isPaused then
|
88
|
+
rcall("ZADD", markerKey, 0, "0")
|
89
|
+
end
|
90
|
+
end
|
82
91
|
local function addJobWithPriority(markerKey, prioritizedKey, priority, jobId, priorityCounterKey, isPaused)
|
83
92
|
local prioCounter = rcall("INCR", priorityCounterKey)
|
84
93
|
local score = priority * 0x100000000 + bit.band(prioCounter, 0xffffffffffff)
|
85
94
|
rcall("ZADD", prioritizedKey, score, jobId)
|
86
|
-
|
87
|
-
rcall("ZADD", markerKey, 0, "0")
|
88
|
-
end
|
95
|
+
addBaseMarkerIfNeeded(markerKey, isPaused)
|
89
96
|
end
|
90
97
|
--[[
|
91
98
|
This function is used to update the parent's dependencies if the job
|
@@ -104,7 +111,7 @@ end
|
|
104
111
|
-- Includes
|
105
112
|
--[[
|
106
113
|
Add delay marker if needed.
|
107
|
-
]]
|
114
|
+
]]
|
108
115
|
-- Includes
|
109
116
|
--[[
|
110
117
|
Function to return the next delayed job timestamp.
|
@@ -127,6 +134,14 @@ local function addDelayMarkerIfNeeded(markerKey, delayedKey)
|
|
127
134
|
rcall("ZADD", markerKey, nextTimestamp, "0")
|
128
135
|
end
|
129
136
|
end
|
137
|
+
--[[
|
138
|
+
Function to add job in target list and add marker if needed.
|
139
|
+
]]
|
140
|
+
-- Includes
|
141
|
+
local function addJobInTargetList(targetKey, markerKey, pushCmd, isPaused, jobId)
|
142
|
+
rcall(pushCmd, targetKey, jobId)
|
143
|
+
addBaseMarkerIfNeeded(markerKey, isPaused)
|
144
|
+
end
|
130
145
|
--[[
|
131
146
|
Function to check for the meta.paused key to decide if we are paused or not
|
132
147
|
(since an empty list and !EXISTS are not really the same).
|
@@ -161,11 +176,10 @@ local function moveParentToWaitIfNeeded(parentQueueKey, parentDependenciesKey,
|
|
161
176
|
addDelayMarkerIfNeeded(parentMarkerKey, parentDelayedKey)
|
162
177
|
else
|
163
178
|
if priority == 0 then
|
164
|
-
local parentTarget,
|
179
|
+
local parentTarget, isParentPaused =
|
165
180
|
getTargetQueueList(parentMetaKey, parentWaitKey,
|
166
181
|
parentPausedKey)
|
167
|
-
|
168
|
-
rcall("ZADD", parentMarkerKey, 0, "0")
|
182
|
+
addJobInTargetList(parentTarget, parentMarkerKey, "RPUSH", isParentPaused, parentId)
|
169
183
|
else
|
170
184
|
local isPaused = isQueuePaused(parentMetaKey)
|
171
185
|
addJobWithPriority(parentMarkerKey,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"addPrioritizedJob-7.js","sourceRoot":"","sources":["../../../src/scripts/addPrioritizedJob-7.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG
|
1
|
+
{"version":3,"file":"addPrioritizedJob-7.js","sourceRoot":"","sources":["../../../src/scripts/addPrioritizedJob-7.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyQf,CAAC;AACF,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,IAAI,EAAE,mBAAmB;IACzB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
|
@@ -48,6 +48,44 @@ local repeatJobKey = args[9]
|
|
48
48
|
local parent = args[8]
|
49
49
|
local parentData
|
50
50
|
-- Includes
|
51
|
+
--[[
|
52
|
+
Function to add job in target list and add marker if needed.
|
53
|
+
]]
|
54
|
+
-- Includes
|
55
|
+
--[[
|
56
|
+
Add marker if needed when a job is available.
|
57
|
+
]]
|
58
|
+
local function addBaseMarkerIfNeeded(markerKey, isPaused)
|
59
|
+
if not isPaused then
|
60
|
+
rcall("ZADD", markerKey, 0, "0")
|
61
|
+
end
|
62
|
+
end
|
63
|
+
local function addJobInTargetList(targetKey, markerKey, pushCmd, isPaused, jobId)
|
64
|
+
rcall(pushCmd, targetKey, jobId)
|
65
|
+
addBaseMarkerIfNeeded(markerKey, isPaused)
|
66
|
+
end
|
67
|
+
--[[
|
68
|
+
Function to get max events value or set by default 10000.
|
69
|
+
]]
|
70
|
+
local function getOrSetMaxEvents(metaKey)
|
71
|
+
local maxEvents = rcall("HGET", metaKey, "opts.maxLenEvents")
|
72
|
+
if not maxEvents then
|
73
|
+
maxEvents = 10000
|
74
|
+
rcall("HSET", metaKey, "opts.maxLenEvents", maxEvents)
|
75
|
+
end
|
76
|
+
return maxEvents
|
77
|
+
end
|
78
|
+
--[[
|
79
|
+
Function to check for the meta.paused key to decide if we are paused or not
|
80
|
+
(since an empty list and !EXISTS are not really the same).
|
81
|
+
]]
|
82
|
+
local function getTargetQueueList(queueMetaKey, waitKey, pausedKey)
|
83
|
+
if rcall("HEXISTS", queueMetaKey, "paused") ~= 1 then
|
84
|
+
return waitKey, false
|
85
|
+
else
|
86
|
+
return pausedKey, true
|
87
|
+
end
|
88
|
+
end
|
51
89
|
--[[
|
52
90
|
Function to store a job
|
53
91
|
]]
|
@@ -90,7 +128,7 @@ end
|
|
90
128
|
-- Includes
|
91
129
|
--[[
|
92
130
|
Add delay marker if needed.
|
93
|
-
]]
|
131
|
+
]]
|
94
132
|
-- Includes
|
95
133
|
--[[
|
96
134
|
Function to return the next delayed job timestamp.
|
@@ -113,34 +151,22 @@ local function addDelayMarkerIfNeeded(markerKey, delayedKey)
|
|
113
151
|
rcall("ZADD", markerKey, nextTimestamp, "0")
|
114
152
|
end
|
115
153
|
end
|
116
|
-
--[[
|
117
|
-
Function to check for the meta.paused key to decide if we are paused or not
|
118
|
-
(since an empty list and !EXISTS are not really the same).
|
119
|
-
]]
|
120
|
-
local function isQueuePaused(queueMetaKey)
|
121
|
-
return rcall("HEXISTS", queueMetaKey, "paused") == 1
|
122
|
-
end
|
123
154
|
--[[
|
124
155
|
Function to add job considering priority.
|
125
156
|
]]
|
157
|
+
-- Includes
|
126
158
|
local function addJobWithPriority(markerKey, prioritizedKey, priority, jobId, priorityCounterKey, isPaused)
|
127
159
|
local prioCounter = rcall("INCR", priorityCounterKey)
|
128
160
|
local score = priority * 0x100000000 + bit.band(prioCounter, 0xffffffffffff)
|
129
161
|
rcall("ZADD", prioritizedKey, score, jobId)
|
130
|
-
|
131
|
-
rcall("ZADD", markerKey, 0, "0")
|
132
|
-
end
|
162
|
+
addBaseMarkerIfNeeded(markerKey, isPaused)
|
133
163
|
end
|
134
164
|
--[[
|
135
165
|
Function to check for the meta.paused key to decide if we are paused or not
|
136
166
|
(since an empty list and !EXISTS are not really the same).
|
137
167
|
]]
|
138
|
-
local function
|
139
|
-
|
140
|
-
return waitKey, false
|
141
|
-
else
|
142
|
-
return pausedKey, true
|
143
|
-
end
|
168
|
+
local function isQueuePaused(queueMetaKey)
|
169
|
+
return rcall("HEXISTS", queueMetaKey, "paused") == 1
|
144
170
|
end
|
145
171
|
local function moveParentToWaitIfNeeded(parentQueueKey, parentDependenciesKey,
|
146
172
|
parentKey, parentId, timestamp)
|
@@ -165,11 +191,10 @@ local function moveParentToWaitIfNeeded(parentQueueKey, parentDependenciesKey,
|
|
165
191
|
addDelayMarkerIfNeeded(parentMarkerKey, parentDelayedKey)
|
166
192
|
else
|
167
193
|
if priority == 0 then
|
168
|
-
local parentTarget,
|
194
|
+
local parentTarget, isParentPaused =
|
169
195
|
getTargetQueueList(parentMetaKey, parentWaitKey,
|
170
196
|
parentPausedKey)
|
171
|
-
|
172
|
-
rcall("ZADD", parentMarkerKey, 0, "0")
|
197
|
+
addJobInTargetList(parentTarget, parentMarkerKey, "RPUSH", isParentPaused, parentId)
|
173
198
|
else
|
174
199
|
local isPaused = isQueuePaused(parentMetaKey)
|
175
200
|
addJobWithPriority(parentMarkerKey,
|
@@ -204,17 +229,6 @@ local function updateExistingJobsParent(parentKey, parent, parentData,
|
|
204
229
|
rcall("HMSET", jobIdKey, "parentKey", parentKey, "parent", parentData)
|
205
230
|
end
|
206
231
|
end
|
207
|
-
--[[
|
208
|
-
Function to get max events value or set by default 10000.
|
209
|
-
]]
|
210
|
-
local function getOrSetMaxEvents(metaKey)
|
211
|
-
local maxEvents = rcall("HGET", metaKey, "opts.maxLenEvents")
|
212
|
-
if not maxEvents then
|
213
|
-
maxEvents = 10000
|
214
|
-
rcall("HSET", metaKey, "opts.maxLenEvents", maxEvents)
|
215
|
-
end
|
216
|
-
return maxEvents
|
217
|
-
end
|
218
232
|
if parentKey ~= nil then
|
219
233
|
if rcall("EXISTS", parentKey) ~= 1 then return -5 end
|
220
234
|
parentData = cjson.encode(parent)
|
@@ -243,13 +257,9 @@ end
|
|
243
257
|
storeJob(eventsKey, jobIdKey, jobId, args[3], ARGV[2], opts, timestamp,
|
244
258
|
parentKey, parentData, repeatJobKey)
|
245
259
|
local target, paused = getTargetQueueList(metaKey, KEYS[1], KEYS[2])
|
246
|
-
if not paused then
|
247
|
-
-- mark that a job is available
|
248
|
-
rcall("ZADD", KEYS[7], 0, "0")
|
249
|
-
end
|
250
260
|
-- LIFO or FIFO
|
251
261
|
local pushCmd = opts['lifo'] and 'RPUSH' or 'LPUSH'
|
252
|
-
|
262
|
+
addJobInTargetList(target, KEYS[7], pushCmd, paused, jobId)
|
253
263
|
-- Emit waiting event
|
254
264
|
rcall("XADD", eventsKey, "MAXLEN", "~", maxEvents, "*", "event", "waiting",
|
255
265
|
"jobId", jobId)
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"addStandardJob-7.js","sourceRoot":"","sources":["../../../src/scripts/addStandardJob-7.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG
|
1
|
+
{"version":3,"file":"addStandardJob-7.js","sourceRoot":"","sources":["../../../src/scripts/addStandardJob-7.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8Qf,CAAC;AACF,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,IAAI,EAAE,gBAAgB;IACtB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
|
@@ -25,6 +25,7 @@ if rcall("EXISTS", KEYS[2]) == 1 then
|
|
25
25
|
end
|
26
26
|
rcall("HSET", KEYS[2], "delay", tonumber(ARGV[1]))
|
27
27
|
rcall("ZADD", KEYS[1], score, jobId)
|
28
|
+
-- TODO: check if we need to evaluate a new marker
|
28
29
|
rcall("XADD", KEYS[3], "*", "event", "delayed", "jobId", jobId, "delay", delayedTimestamp)
|
29
30
|
return 0
|
30
31
|
else
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"changeDelay-3.js","sourceRoot":"","sources":["../../../src/scripts/changeDelay-3.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG
|
1
|
+
{"version":3,"file":"changeDelay-3.js","sourceRoot":"","sources":["../../../src/scripts/changeDelay-3.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAgCZ,CAAC;AACL,MAAM,CAAC,MAAM,WAAW,GAAG;IACzB,IAAI,EAAE,aAAa;IACnB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
|
@@ -30,24 +30,20 @@ end
|
|
30
30
|
--[[
|
31
31
|
Function to add job considering priority.
|
32
32
|
]]
|
33
|
+
-- Includes
|
34
|
+
--[[
|
35
|
+
Add marker if needed when a job is available.
|
36
|
+
]]
|
37
|
+
local function addBaseMarkerIfNeeded(markerKey, isPaused)
|
38
|
+
if not isPaused then
|
39
|
+
rcall("ZADD", markerKey, 0, "0")
|
40
|
+
end
|
41
|
+
end
|
33
42
|
local function addJobWithPriority(markerKey, prioritizedKey, priority, jobId, priorityCounterKey, isPaused)
|
34
43
|
local prioCounter = rcall("INCR", priorityCounterKey)
|
35
44
|
local score = priority * 0x100000000 + bit.band(prioCounter, 0xffffffffffff)
|
36
45
|
rcall("ZADD", prioritizedKey, score, jobId)
|
37
|
-
|
38
|
-
rcall("ZADD", markerKey, 0, "0")
|
39
|
-
end
|
40
|
-
end
|
41
|
-
--[[
|
42
|
-
Function to check for the meta.paused key to decide if we are paused or not
|
43
|
-
(since an empty list and !EXISTS are not really the same).
|
44
|
-
]]
|
45
|
-
local function getTargetQueueList(queueMetaKey, waitKey, pausedKey)
|
46
|
-
if rcall("HEXISTS", queueMetaKey, "paused") ~= 1 then
|
47
|
-
return waitKey, false
|
48
|
-
else
|
49
|
-
return pausedKey, true
|
50
|
-
end
|
46
|
+
addBaseMarkerIfNeeded(markerKey, isPaused)
|
51
47
|
end
|
52
48
|
if rcall("EXISTS", jobKey) == 1 then
|
53
49
|
local metaKey = KEYS[3]
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"changePriority-6.js","sourceRoot":"","sources":["../../../src/scripts/changePriority-6.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG
|
1
|
+
{"version":3,"file":"changePriority-6.js","sourceRoot":"","sources":["../../../src/scripts/changePriority-6.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAuEf,CAAC;AACF,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,IAAI,EAAE,gBAAgB;IACtB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
|
@@ -14,8 +14,8 @@ export * from './getStateV2-8';
|
|
14
14
|
export * from './isFinished-3';
|
15
15
|
export * from './isJobInList-1';
|
16
16
|
export * from './moveJobFromActiveToWait-9';
|
17
|
-
export * from './moveJobsToWait-
|
18
|
-
export * from './moveStalledJobsToWait-
|
17
|
+
export * from './moveJobsToWait-7';
|
18
|
+
export * from './moveStalledJobsToWait-9';
|
19
19
|
export * from './moveToActive-11';
|
20
20
|
export * from './moveToDelayed-7';
|
21
21
|
export * from './moveToFinished-14';
|