bullmq 4.16.0 → 5.0.0
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/flow-producer.js +3 -10
- package/dist/cjs/classes/flow-producer.js.map +1 -1
- package/dist/cjs/classes/job.js +21 -11
- package/dist/cjs/classes/job.js.map +1 -1
- package/dist/cjs/classes/queue-base.js +2 -9
- package/dist/cjs/classes/queue-base.js.map +1 -1
- package/dist/cjs/classes/queue-events.js +3 -1
- package/dist/cjs/classes/queue-events.js.map +1 -1
- package/dist/cjs/classes/queue-keys.js +1 -0
- package/dist/cjs/classes/queue-keys.js.map +1 -1
- package/dist/cjs/classes/redis-connection.js +9 -7
- package/dist/cjs/classes/redis-connection.js.map +1 -1
- package/dist/cjs/classes/scripts.js +34 -34
- package/dist/cjs/classes/scripts.js.map +1 -1
- package/dist/cjs/classes/worker.js +41 -37
- package/dist/cjs/classes/worker.js.map +1 -1
- package/dist/cjs/commands/{addDelayedJob-7.lua → addDelayedJob-6.lua} +18 -22
- package/dist/cjs/commands/addParentJob-4.lua +0 -2
- package/dist/{esm/commands/addPrioritizedJob-8.lua → cjs/commands/addPrioritizedJob-7.lua} +18 -24
- package/dist/cjs/commands/{addStandardJob-6.lua → addStandardJob-7.lua} +6 -2
- package/dist/cjs/commands/changePriority-6.lua +57 -0
- package/dist/cjs/commands/getCounts-1.lua +1 -0
- package/dist/cjs/commands/getRanges-1.lua +1 -0
- package/dist/cjs/commands/includes/addDelayMarkerIfNeeded.lua +5 -19
- package/dist/cjs/commands/includes/addJobWithPriority.lua +3 -7
- package/dist/cjs/commands/includes/checkStalledJobs.lua +1 -1
- package/dist/cjs/commands/includes/isQueuePaused.lua +7 -0
- package/dist/cjs/commands/includes/moveParentToWaitIfNeeded.lua +39 -30
- package/dist/cjs/commands/includes/prepareJobForProcessing.lua +1 -1
- package/dist/cjs/commands/includes/promoteDelayedJobs.lua +7 -4
- package/dist/{esm/commands/moveToActive-10.lua → cjs/commands/moveToActive-11.lua} +18 -29
- package/dist/cjs/commands/moveToDelayed-7.lua +77 -0
- package/dist/cjs/commands/{moveToFinished-13.lua → moveToFinished-14.lua} +29 -22
- package/dist/cjs/commands/moveToWaitingChildren-4.lua +7 -4
- package/dist/cjs/commands/pause-7.lua +41 -0
- package/dist/cjs/commands/promote-8.lua +60 -0
- package/dist/cjs/commands/{retryJob-9.lua → retryJob-10.lua} +16 -11
- package/dist/cjs/scripts/{addDelayedJob-7.js → addDelayedJob-6.js} +77 -88
- package/dist/cjs/scripts/{moveToActive-10.js.map → addDelayedJob-6.js.map} +1 -1
- package/dist/cjs/scripts/addParentJob-4.js +51 -61
- package/dist/cjs/scripts/addParentJob-4.js.map +1 -1
- package/dist/cjs/scripts/{addPrioritizedJob-8.js → addPrioritizedJob-7.js} +80 -93
- package/dist/cjs/scripts/addPrioritizedJob-7.js.map +1 -0
- package/dist/cjs/scripts/{addStandardJob-6.js → addStandardJob-7.js} +58 -63
- package/dist/cjs/scripts/addStandardJob-7.js.map +1 -0
- package/dist/cjs/scripts/changePriority-6.js +85 -0
- package/dist/cjs/scripts/changePriority-6.js.map +1 -0
- package/dist/cjs/scripts/getCounts-1.js +1 -0
- package/dist/cjs/scripts/getCounts-1.js.map +1 -1
- package/dist/cjs/scripts/getRanges-1.js +1 -0
- package/dist/cjs/scripts/getRanges-1.js.map +1 -1
- package/dist/cjs/scripts/index.js +10 -10
- package/dist/cjs/scripts/index.js.map +1 -1
- package/dist/cjs/scripts/moveStalledJobsToWait-8.js +1 -0
- package/dist/cjs/scripts/moveStalledJobsToWait-8.js.map +1 -1
- package/dist/cjs/scripts/{moveToActive-10.js → moveToActive-11.js} +30 -48
- package/dist/cjs/scripts/moveToActive-11.js.map +1 -0
- package/dist/cjs/scripts/moveToDelayed-7.js +103 -0
- package/dist/cjs/scripts/moveToDelayed-7.js.map +1 -0
- package/dist/cjs/scripts/{moveToFinished-13.js → moveToFinished-14.js} +89 -88
- package/dist/cjs/scripts/{moveToFinished-13.js.map → moveToFinished-14.js.map} +1 -1
- package/dist/cjs/scripts/moveToWaitingChildren-4.js +6 -3
- package/dist/cjs/scripts/moveToWaitingChildren-4.js.map +1 -1
- package/dist/cjs/scripts/pause-7.js +67 -0
- package/dist/cjs/scripts/pause-7.js.map +1 -0
- package/dist/cjs/scripts/promote-8.js +79 -0
- package/dist/cjs/scripts/promote-8.js.map +1 -0
- package/dist/cjs/scripts/{retryJob-9.js → retryJob-10.js} +26 -32
- package/dist/cjs/scripts/retryJob-10.js.map +1 -0
- package/dist/cjs/tsconfig-cjs.tsbuildinfo +1 -1
- package/dist/esm/classes/flow-producer.js +3 -10
- package/dist/esm/classes/flow-producer.js.map +1 -1
- package/dist/esm/classes/job.d.ts +5 -0
- package/dist/esm/classes/job.js +21 -11
- package/dist/esm/classes/job.js.map +1 -1
- package/dist/esm/classes/queue-base.js +2 -9
- package/dist/esm/classes/queue-base.js.map +1 -1
- package/dist/esm/classes/queue-events.js +3 -1
- package/dist/esm/classes/queue-events.js.map +1 -1
- package/dist/esm/classes/queue-keys.js +1 -0
- package/dist/esm/classes/queue-keys.js.map +1 -1
- package/dist/esm/classes/redis-connection.js +9 -7
- package/dist/esm/classes/redis-connection.js.map +1 -1
- package/dist/esm/classes/scripts.d.ts +4 -4
- package/dist/esm/classes/scripts.js +34 -34
- package/dist/esm/classes/scripts.js.map +1 -1
- package/dist/esm/classes/worker.d.ts +4 -2
- package/dist/esm/classes/worker.js +41 -37
- package/dist/esm/classes/worker.js.map +1 -1
- package/dist/esm/commands/{addDelayedJob-7.lua → addDelayedJob-6.lua} +18 -22
- package/dist/esm/commands/addParentJob-4.lua +0 -2
- package/dist/{cjs/commands/addPrioritizedJob-8.lua → esm/commands/addPrioritizedJob-7.lua} +18 -24
- package/dist/esm/commands/{addStandardJob-6.lua → addStandardJob-7.lua} +6 -2
- package/dist/esm/commands/changePriority-6.lua +57 -0
- package/dist/esm/commands/getCounts-1.lua +1 -0
- package/dist/esm/commands/getRanges-1.lua +1 -0
- package/dist/esm/commands/includes/addDelayMarkerIfNeeded.lua +5 -19
- package/dist/esm/commands/includes/addJobWithPriority.lua +3 -7
- package/dist/esm/commands/includes/checkStalledJobs.lua +1 -1
- package/dist/esm/commands/includes/isQueuePaused.lua +7 -0
- package/dist/esm/commands/includes/moveParentToWaitIfNeeded.lua +39 -30
- package/dist/esm/commands/includes/prepareJobForProcessing.lua +1 -1
- package/dist/esm/commands/includes/promoteDelayedJobs.lua +7 -4
- package/dist/{cjs/commands/moveToActive-10.lua → esm/commands/moveToActive-11.lua} +18 -29
- package/dist/esm/commands/moveToDelayed-7.lua +77 -0
- package/dist/esm/commands/{moveToFinished-13.lua → moveToFinished-14.lua} +29 -22
- package/dist/esm/commands/moveToWaitingChildren-4.lua +7 -4
- package/dist/esm/commands/pause-7.lua +41 -0
- package/dist/esm/commands/promote-8.lua +60 -0
- package/dist/esm/commands/{retryJob-9.lua → retryJob-10.lua} +16 -11
- package/dist/esm/interfaces/job-json.d.ts +4 -1
- package/dist/esm/interfaces/minimal-job.d.ts +3 -0
- package/dist/esm/interfaces/queue-options.d.ts +1 -1
- package/dist/esm/scripts/{addDelayedJob-7.js → addDelayedJob-6.js} +77 -88
- package/dist/esm/scripts/{moveToActive-10.js.map → addDelayedJob-6.js.map} +1 -1
- package/dist/esm/scripts/addParentJob-4.js +51 -61
- package/dist/esm/scripts/addParentJob-4.js.map +1 -1
- package/dist/esm/scripts/{addPrioritizedJob-8.js → addPrioritizedJob-7.js} +80 -93
- package/dist/esm/scripts/addPrioritizedJob-7.js.map +1 -0
- package/dist/esm/scripts/{addStandardJob-6.js → addStandardJob-7.js} +58 -63
- package/dist/esm/scripts/addStandardJob-7.js.map +1 -0
- package/dist/esm/scripts/changePriority-6.js +82 -0
- package/dist/esm/scripts/changePriority-6.js.map +1 -0
- package/dist/esm/scripts/getCounts-1.js +1 -0
- package/dist/esm/scripts/getCounts-1.js.map +1 -1
- package/dist/esm/scripts/getRanges-1.js +1 -0
- package/dist/esm/scripts/getRanges-1.js.map +1 -1
- package/dist/esm/scripts/index.d.ts +10 -10
- package/dist/esm/scripts/index.js +10 -10
- package/dist/esm/scripts/index.js.map +1 -1
- package/dist/esm/scripts/moveStalledJobsToWait-8.js +1 -0
- package/dist/esm/scripts/moveStalledJobsToWait-8.js.map +1 -1
- package/dist/esm/scripts/{moveToActive-10.js → moveToActive-11.js} +30 -48
- package/dist/esm/scripts/moveToActive-11.js.map +1 -0
- package/dist/esm/scripts/moveToDelayed-7.js +100 -0
- package/dist/esm/scripts/moveToDelayed-7.js.map +1 -0
- package/dist/esm/scripts/{moveToFinished-13.js → moveToFinished-14.js} +89 -88
- package/dist/esm/scripts/{moveToFinished-13.js.map → moveToFinished-14.js.map} +1 -1
- package/dist/esm/scripts/moveToWaitingChildren-4.js +6 -3
- package/dist/esm/scripts/moveToWaitingChildren-4.js.map +1 -1
- package/dist/esm/scripts/pause-7.js +64 -0
- package/dist/esm/scripts/pause-7.js.map +1 -0
- package/dist/esm/scripts/promote-8.js +76 -0
- package/dist/esm/scripts/promote-8.js.map +1 -0
- package/dist/esm/scripts/{retryJob-9.js → retryJob-10.js} +26 -32
- package/dist/esm/scripts/retryJob-10.js.map +1 -0
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/dist/cjs/commands/changePriority-5.lua +0 -52
- package/dist/cjs/commands/includes/addPriorityMarkerIfNeeded.lua +0 -12
- package/dist/cjs/commands/moveToDelayed-8.lua +0 -72
- package/dist/cjs/commands/pause-5.lua +0 -36
- package/dist/cjs/commands/promote-7.lua +0 -57
- package/dist/cjs/scripts/addDelayedJob-7.js.map +0 -1
- package/dist/cjs/scripts/addPrioritizedJob-8.js.map +0 -1
- package/dist/cjs/scripts/addStandardJob-6.js.map +0 -1
- package/dist/cjs/scripts/changePriority-5.js +0 -87
- package/dist/cjs/scripts/changePriority-5.js.map +0 -1
- package/dist/cjs/scripts/moveToDelayed-8.js +0 -168
- package/dist/cjs/scripts/moveToDelayed-8.js.map +0 -1
- package/dist/cjs/scripts/pause-5.js +0 -48
- package/dist/cjs/scripts/pause-5.js.map +0 -1
- package/dist/cjs/scripts/promote-7.js +0 -87
- package/dist/cjs/scripts/promote-7.js.map +0 -1
- package/dist/cjs/scripts/retryJob-9.js.map +0 -1
- package/dist/esm/commands/changePriority-5.lua +0 -52
- package/dist/esm/commands/includes/addPriorityMarkerIfNeeded.lua +0 -12
- package/dist/esm/commands/moveToDelayed-8.lua +0 -72
- package/dist/esm/commands/pause-5.lua +0 -36
- package/dist/esm/commands/promote-7.lua +0 -57
- package/dist/esm/scripts/addDelayedJob-7.js.map +0 -1
- package/dist/esm/scripts/addPrioritizedJob-8.js.map +0 -1
- package/dist/esm/scripts/addStandardJob-6.js.map +0 -1
- package/dist/esm/scripts/changePriority-5.js +0 -84
- package/dist/esm/scripts/changePriority-5.js.map +0 -1
- package/dist/esm/scripts/moveToDelayed-8.js +0 -165
- package/dist/esm/scripts/moveToDelayed-8.js.map +0 -1
- package/dist/esm/scripts/pause-5.js +0 -45
- package/dist/esm/scripts/pause-5.js.map +0 -1
- package/dist/esm/scripts/promote-7.js +0 -84
- package/dist/esm/scripts/promote-7.js.map +0 -1
- package/dist/esm/scripts/retryJob-9.js.map +0 -1
- /package/dist/esm/scripts/{addDelayedJob-7.d.ts → addDelayedJob-6.d.ts} +0 -0
- /package/dist/esm/scripts/{addPrioritizedJob-8.d.ts → addPrioritizedJob-7.d.ts} +0 -0
- /package/dist/esm/scripts/{addStandardJob-6.d.ts → addStandardJob-7.d.ts} +0 -0
- /package/dist/esm/scripts/{changePriority-5.d.ts → changePriority-6.d.ts} +0 -0
- /package/dist/esm/scripts/{moveToActive-10.d.ts → moveToActive-11.d.ts} +0 -0
- /package/dist/esm/scripts/{moveToDelayed-8.d.ts → moveToDelayed-7.d.ts} +0 -0
- /package/dist/esm/scripts/{moveToFinished-13.d.ts → moveToFinished-14.d.ts} +0 -0
- /package/dist/esm/scripts/{pause-5.d.ts → pause-7.d.ts} +0 -0
- /package/dist/esm/scripts/{promote-7.d.ts → promote-8.d.ts} +0 -0
- /package/dist/esm/scripts/{retryJob-9.d.ts → retryJob-10.d.ts} +0 -0
@@ -2,15 +2,16 @@
|
|
2
2
|
Retries a failed job by moving it back to the wait queue.
|
3
3
|
|
4
4
|
Input:
|
5
|
-
KEYS[1]
|
6
|
-
KEYS[2]
|
7
|
-
KEYS[3]
|
8
|
-
KEYS[4]
|
9
|
-
KEYS[5]
|
10
|
-
KEYS[6]
|
11
|
-
KEYS[7]
|
12
|
-
KEYS[8]
|
13
|
-
KEYS[9]
|
5
|
+
KEYS[1] 'active',
|
6
|
+
KEYS[2] 'wait'
|
7
|
+
KEYS[3] 'paused'
|
8
|
+
KEYS[4] job key
|
9
|
+
KEYS[5] 'meta'
|
10
|
+
KEYS[6] events stream
|
11
|
+
KEYS[7] delayed key
|
12
|
+
KEYS[8] prioritized key
|
13
|
+
KEYS[9] 'pc' priority counter
|
14
|
+
KEYS[10] 'marker'
|
14
15
|
|
15
16
|
ARGV[1] key prefix
|
16
17
|
ARGV[2] timestamp
|
@@ -34,9 +35,11 @@ local rcall = redis.call
|
|
34
35
|
--- @include "includes/promoteDelayedJobs"
|
35
36
|
|
36
37
|
local target, paused = getTargetQueueList(KEYS[5], KEYS[2], KEYS[3])
|
38
|
+
local markerKey = KEYS[10]
|
39
|
+
|
37
40
|
-- Check if there are delayed jobs that we can move to wait.
|
38
41
|
-- test example: when there are delayed jobs between retries
|
39
|
-
promoteDelayedJobs(KEYS[7],
|
42
|
+
promoteDelayedJobs(KEYS[7], markerKey, target, KEYS[8], KEYS[6], ARGV[1], ARGV[2], KEYS[9], paused)
|
40
43
|
|
41
44
|
if rcall("EXISTS", KEYS[4]) == 1 then
|
42
45
|
|
@@ -57,9 +60,11 @@ if rcall("EXISTS", KEYS[4]) == 1 then
|
|
57
60
|
if priority == 0 then
|
58
61
|
rcall(ARGV[3], target, ARGV[4])
|
59
62
|
else
|
60
|
-
addJobWithPriority(
|
63
|
+
addJobWithPriority(markerKey, KEYS[8], priority, ARGV[4], KEYS[9], paused)
|
61
64
|
end
|
62
65
|
|
66
|
+
rcall("HINCRBY", KEYS[4], "atm", 1)
|
67
|
+
|
63
68
|
local maxEvents = rcall("HGET", KEYS[5], "opts.maxLenEvents") or 10000
|
64
69
|
|
65
70
|
-- Emit waiting event
|
@@ -9,13 +9,12 @@ const content = `--[[
|
|
9
9
|
- adds to delayed zset.
|
10
10
|
- Emits a global event 'delayed' if the job is delayed.
|
11
11
|
Input:
|
12
|
-
KEYS[1] '
|
13
|
-
KEYS[2] '
|
14
|
-
KEYS[3] '
|
15
|
-
KEYS[4] '
|
16
|
-
KEYS[5] '
|
17
|
-
KEYS[6]
|
18
|
-
KEYS[7] events stream key
|
12
|
+
KEYS[1] 'marker',
|
13
|
+
KEYS[2] 'meta'
|
14
|
+
KEYS[3] 'id'
|
15
|
+
KEYS[4] 'delayed'
|
16
|
+
KEYS[5] 'completed'
|
17
|
+
KEYS[6] events stream key
|
19
18
|
ARGV[1] msgpacked arguments array
|
20
19
|
[1] key prefix,
|
21
20
|
[2] custom id (use custom instead of one generated automatically)
|
@@ -32,13 +31,11 @@ const content = `--[[
|
|
32
31
|
jobId - OK
|
33
32
|
-5 - Missing parent key
|
34
33
|
]]
|
35
|
-
local
|
36
|
-
local
|
37
|
-
local
|
38
|
-
local
|
39
|
-
local
|
40
|
-
local completedKey = KEYS[6]
|
41
|
-
local eventsKey = KEYS[7]
|
34
|
+
local metaKey = KEYS[2]
|
35
|
+
local idKey = KEYS[3]
|
36
|
+
local delayedKey = KEYS[4]
|
37
|
+
local completedKey = KEYS[5]
|
38
|
+
local eventsKey = KEYS[6]
|
42
39
|
local jobId
|
43
40
|
local jobIdKey
|
44
41
|
local rcall = redis.call
|
@@ -77,7 +74,7 @@ local function storeJob(eventsKey, jobIdKey, jobId, name, data, opts, timestamp,
|
|
77
74
|
end
|
78
75
|
--[[
|
79
76
|
Add delay marker if needed.
|
80
|
-
]]
|
77
|
+
]]
|
81
78
|
-- Includes
|
82
79
|
--[[
|
83
80
|
Function to return the next delayed job timestamp.
|
@@ -92,36 +89,20 @@ local function getNextDelayedTimestamp(delayedKey)
|
|
92
89
|
return nextTimestamp
|
93
90
|
end
|
94
91
|
end
|
95
|
-
local function addDelayMarkerIfNeeded(
|
96
|
-
local waitLen = rcall("LLEN", targetKey)
|
97
|
-
if waitLen <= 1 then
|
92
|
+
local function addDelayMarkerIfNeeded(markerKey, delayedKey)
|
98
93
|
local nextTimestamp = getNextDelayedTimestamp(delayedKey)
|
99
94
|
if nextTimestamp ~= nil then
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
local marker = rcall("LINDEX", targetKey, 0)
|
104
|
-
local oldTimestamp = tonumber(marker:sub(3))
|
105
|
-
if oldTimestamp and oldTimestamp > nextTimestamp then
|
106
|
-
rcall("LSET", targetKey, 0, "0:" .. nextTimestamp)
|
107
|
-
end
|
108
|
-
else
|
109
|
-
-- if there is no marker, then we need to add one
|
110
|
-
rcall("LPUSH", targetKey, "0:" .. nextTimestamp)
|
111
|
-
end
|
95
|
+
-- Replace the score of the marker with the newest known
|
96
|
+
-- next timestamp.
|
97
|
+
rcall("ZADD", markerKey, nextTimestamp, "0")
|
112
98
|
end
|
113
|
-
end
|
114
99
|
end
|
115
100
|
--[[
|
116
101
|
Function to check for the meta.paused key to decide if we are paused or not
|
117
102
|
(since an empty list and !EXISTS are not really the same).
|
118
103
|
]]
|
119
|
-
local function
|
120
|
-
|
121
|
-
return waitKey, false
|
122
|
-
else
|
123
|
-
return pausedKey, true
|
124
|
-
end
|
104
|
+
local function isQueuePaused(queueMetaKey)
|
105
|
+
return rcall("HEXISTS", queueMetaKey, "paused") == 1
|
125
106
|
end
|
126
107
|
--[[
|
127
108
|
Validate and move or add dependencies to parent.
|
@@ -134,56 +115,64 @@ end
|
|
134
115
|
--[[
|
135
116
|
Function to add job considering priority.
|
136
117
|
]]
|
137
|
-
|
138
|
-
--[[
|
139
|
-
Function priority marker to wait if needed
|
140
|
-
in order to wake up our workers and to respect priority
|
141
|
-
order as much as possible
|
142
|
-
]]
|
143
|
-
local function addPriorityMarkerIfNeeded(waitKey)
|
144
|
-
local waitLen = rcall("LLEN", waitKey)
|
145
|
-
if waitLen == 0 then
|
146
|
-
rcall("LPUSH", waitKey, "0:0")
|
147
|
-
end
|
148
|
-
end
|
149
|
-
local function addJobWithPriority(waitKey, prioritizedKey, priority, paused, jobId, priorityCounterKey)
|
118
|
+
local function addJobWithPriority(markerKey, prioritizedKey, priority, jobId, priorityCounterKey, isPaused)
|
150
119
|
local prioCounter = rcall("INCR", priorityCounterKey)
|
151
120
|
local score = priority * 0x100000000 + bit.band(prioCounter, 0xffffffffffff)
|
152
121
|
rcall("ZADD", prioritizedKey, score, jobId)
|
153
|
-
if not
|
154
|
-
|
122
|
+
if not isPaused then
|
123
|
+
rcall("ZADD", markerKey, 0, "0")
|
155
124
|
end
|
156
125
|
end
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
local delay = tonumber(jobAttributes[2]) or 0
|
167
|
-
if delay > 0 then
|
168
|
-
local delayedTimestamp = tonumber(timestamp) + delay
|
169
|
-
local score = delayedTimestamp * 0x1000
|
170
|
-
local parentDelayedKey = parentQueueKey .. ":delayed"
|
171
|
-
rcall("ZADD", parentDelayedKey, score, parentId)
|
172
|
-
rcall("XADD", parentQueueKey .. ":events", "*", "event", "delayed", "jobId", parentId,
|
173
|
-
"delay", delayedTimestamp)
|
174
|
-
addDelayMarkerIfNeeded(parentTarget, parentDelayedKey)
|
175
|
-
else
|
176
|
-
if priority == 0 then
|
177
|
-
rcall("RPUSH", parentTarget, parentId)
|
178
|
-
else
|
179
|
-
addJobWithPriority(parentWaitKey, parentQueueKey .. ":prioritized", priority, paused,
|
180
|
-
parentId, parentQueueKey .. ":pc")
|
181
|
-
end
|
182
|
-
rcall("XADD", parentQueueKey .. ":events", "*", "event", "waiting", "jobId", parentId,
|
183
|
-
"prev", "waiting-children")
|
184
|
-
end
|
126
|
+
--[[
|
127
|
+
Function to check for the meta.paused key to decide if we are paused or not
|
128
|
+
(since an empty list and !EXISTS are not really the same).
|
129
|
+
]]
|
130
|
+
local function getTargetQueueList(queueMetaKey, waitKey, pausedKey)
|
131
|
+
if rcall("HEXISTS", queueMetaKey, "paused") ~= 1 then
|
132
|
+
return waitKey, false
|
133
|
+
else
|
134
|
+
return pausedKey, true
|
185
135
|
end
|
186
136
|
end
|
137
|
+
local function moveParentToWaitIfNeeded(parentQueueKey, parentDependenciesKey,
|
138
|
+
parentKey, parentId, timestamp)
|
139
|
+
local isParentActive = rcall("ZSCORE",
|
140
|
+
parentQueueKey .. ":waiting-children", parentId)
|
141
|
+
if rcall("SCARD", parentDependenciesKey) == 0 and isParentActive then
|
142
|
+
rcall("ZREM", parentQueueKey .. ":waiting-children", parentId)
|
143
|
+
local parentWaitKey = parentQueueKey .. ":wait"
|
144
|
+
local parentPausedKey = parentQueueKey .. ":paused"
|
145
|
+
local parentMetaKey = parentQueueKey .. ":meta"
|
146
|
+
local parentMarkerKey = parentQueueKey .. ":marker"
|
147
|
+
local jobAttributes = rcall("HMGET", parentKey, "priority", "delay")
|
148
|
+
local priority = tonumber(jobAttributes[1]) or 0
|
149
|
+
local delay = tonumber(jobAttributes[2]) or 0
|
150
|
+
if delay > 0 then
|
151
|
+
local delayedTimestamp = tonumber(timestamp) + delay
|
152
|
+
local score = delayedTimestamp * 0x1000
|
153
|
+
local parentDelayedKey = parentQueueKey .. ":delayed"
|
154
|
+
rcall("ZADD", parentDelayedKey, score, parentId)
|
155
|
+
rcall("XADD", parentQueueKey .. ":events", "*", "event", "delayed",
|
156
|
+
"jobId", parentId, "delay", delayedTimestamp)
|
157
|
+
addDelayMarkerIfNeeded(parentMarkerKey, parentDelayedKey)
|
158
|
+
else
|
159
|
+
if priority == 0 then
|
160
|
+
local parentTarget, _paused =
|
161
|
+
getTargetQueueList(parentMetaKey, parentWaitKey,
|
162
|
+
parentPausedKey)
|
163
|
+
rcall("RPUSH", parentTarget, parentId)
|
164
|
+
rcall("ZADD", parentMarkerKey, 0, "0")
|
165
|
+
else
|
166
|
+
local isPaused = isQueuePaused(parentMetaKey)
|
167
|
+
addJobWithPriority(parentMarkerKey,
|
168
|
+
parentQueueKey .. ":prioritized", priority,
|
169
|
+
parentId, parentQueueKey .. ":pc", isPaused)
|
170
|
+
end
|
171
|
+
rcall("XADD", parentQueueKey .. ":events", "*", "event", "waiting",
|
172
|
+
"jobId", parentId, "prev", "waiting-children")
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
187
176
|
local function updateParentDepsIfNeeded(parentKey, parentQueueKey, parentDependenciesKey,
|
188
177
|
parentId, jobIdKey, returnvalue, timestamp )
|
189
178
|
local processedSet = parentKey .. ":processed"
|
@@ -255,13 +244,13 @@ local score = delayedTimestamp * 0x1000 + bit.band(jobCounter, 0xfff)
|
|
255
244
|
rcall("ZADD", delayedKey, score, jobId)
|
256
245
|
rcall("XADD", eventsKey, "MAXLEN", "~", maxEvents, "*", "event", "delayed",
|
257
246
|
"jobId", jobId, "delay", delayedTimestamp)
|
258
|
-
--
|
259
|
-
|
260
|
-
|
261
|
-
|
247
|
+
-- mark that a delayed job is available
|
248
|
+
local isPaused = isQueuePaused(metaKey)
|
249
|
+
if not isPaused then
|
250
|
+
local markerKey = KEYS[1]
|
251
|
+
addDelayMarkerIfNeeded(markerKey, delayedKey)
|
252
|
+
end
|
262
253
|
-- Check if this job is a child of another job, if so add it to the parents dependencies
|
263
|
-
-- TODO: Should not be possible to add a child job to a parent that is not in the "waiting-children" status.
|
264
|
-
-- fail in this case.
|
265
254
|
if parentDependenciesKey ~= nil then
|
266
255
|
rcall("SADD", parentDependenciesKey, jobIdKey)
|
267
256
|
end
|
@@ -270,6 +259,6 @@ return jobId .. "" -- convert to string
|
|
270
259
|
exports.addDelayedJob = {
|
271
260
|
name: 'addDelayedJob',
|
272
261
|
content,
|
273
|
-
keys:
|
262
|
+
keys: 6,
|
274
263
|
};
|
275
|
-
//# sourceMappingURL=addDelayedJob-
|
264
|
+
//# sourceMappingURL=addDelayedJob-6.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"
|
1
|
+
{"version":3,"file":"addDelayedJob-6.js","sourceRoot":"","sources":["../../../src/scripts/addDelayedJob-6.ts"],"names":[],"mappings":";;;AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8Pf,CAAC;AACW,QAAA,aAAa,GAAG;IAC3B,IAAI,EAAE,eAAe;IACrB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
|
@@ -77,7 +77,7 @@ end
|
|
77
77
|
-- Includes
|
78
78
|
--[[
|
79
79
|
Add delay marker if needed.
|
80
|
-
]]
|
80
|
+
]]
|
81
81
|
-- Includes
|
82
82
|
--[[
|
83
83
|
Function to return the next delayed job timestamp.
|
@@ -92,47 +92,30 @@ local function getNextDelayedTimestamp(delayedKey)
|
|
92
92
|
return nextTimestamp
|
93
93
|
end
|
94
94
|
end
|
95
|
-
local function addDelayMarkerIfNeeded(
|
96
|
-
local waitLen = rcall("LLEN", targetKey)
|
97
|
-
if waitLen <= 1 then
|
95
|
+
local function addDelayMarkerIfNeeded(markerKey, delayedKey)
|
98
96
|
local nextTimestamp = getNextDelayedTimestamp(delayedKey)
|
99
97
|
if nextTimestamp ~= nil then
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
local marker = rcall("LINDEX", targetKey, 0)
|
104
|
-
local oldTimestamp = tonumber(marker:sub(3))
|
105
|
-
if oldTimestamp and oldTimestamp > nextTimestamp then
|
106
|
-
rcall("LSET", targetKey, 0, "0:" .. nextTimestamp)
|
107
|
-
end
|
108
|
-
else
|
109
|
-
-- if there is no marker, then we need to add one
|
110
|
-
rcall("LPUSH", targetKey, "0:" .. nextTimestamp)
|
111
|
-
end
|
98
|
+
-- Replace the score of the marker with the newest known
|
99
|
+
-- next timestamp.
|
100
|
+
rcall("ZADD", markerKey, nextTimestamp, "0")
|
112
101
|
end
|
113
|
-
end
|
114
102
|
end
|
115
103
|
--[[
|
116
|
-
Function to
|
104
|
+
Function to check for the meta.paused key to decide if we are paused or not
|
105
|
+
(since an empty list and !EXISTS are not really the same).
|
117
106
|
]]
|
118
|
-
|
107
|
+
local function isQueuePaused(queueMetaKey)
|
108
|
+
return rcall("HEXISTS", queueMetaKey, "paused") == 1
|
109
|
+
end
|
119
110
|
--[[
|
120
|
-
Function
|
121
|
-
in order to wake up our workers and to respect priority
|
122
|
-
order as much as possible
|
111
|
+
Function to add job considering priority.
|
123
112
|
]]
|
124
|
-
local function
|
125
|
-
local waitLen = rcall("LLEN", waitKey)
|
126
|
-
if waitLen == 0 then
|
127
|
-
rcall("LPUSH", waitKey, "0:0")
|
128
|
-
end
|
129
|
-
end
|
130
|
-
local function addJobWithPriority(waitKey, prioritizedKey, priority, paused, jobId, priorityCounterKey)
|
113
|
+
local function addJobWithPriority(markerKey, prioritizedKey, priority, jobId, priorityCounterKey, isPaused)
|
131
114
|
local prioCounter = rcall("INCR", priorityCounterKey)
|
132
115
|
local score = priority * 0x100000000 + bit.band(prioCounter, 0xffffffffffff)
|
133
116
|
rcall("ZADD", prioritizedKey, score, jobId)
|
134
|
-
if not
|
135
|
-
|
117
|
+
if not isPaused then
|
118
|
+
rcall("ZADD", markerKey, 0, "0")
|
136
119
|
end
|
137
120
|
end
|
138
121
|
--[[
|
@@ -146,35 +129,44 @@ local function getTargetQueueList(queueMetaKey, waitKey, pausedKey)
|
|
146
129
|
return pausedKey, true
|
147
130
|
end
|
148
131
|
end
|
149
|
-
local function moveParentToWaitIfNeeded(parentQueueKey, parentDependenciesKey,
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
132
|
+
local function moveParentToWaitIfNeeded(parentQueueKey, parentDependenciesKey,
|
133
|
+
parentKey, parentId, timestamp)
|
134
|
+
local isParentActive = rcall("ZSCORE",
|
135
|
+
parentQueueKey .. ":waiting-children", parentId)
|
136
|
+
if rcall("SCARD", parentDependenciesKey) == 0 and isParentActive then
|
137
|
+
rcall("ZREM", parentQueueKey .. ":waiting-children", parentId)
|
138
|
+
local parentWaitKey = parentQueueKey .. ":wait"
|
139
|
+
local parentPausedKey = parentQueueKey .. ":paused"
|
140
|
+
local parentMetaKey = parentQueueKey .. ":meta"
|
141
|
+
local parentMarkerKey = parentQueueKey .. ":marker"
|
142
|
+
local jobAttributes = rcall("HMGET", parentKey, "priority", "delay")
|
143
|
+
local priority = tonumber(jobAttributes[1]) or 0
|
144
|
+
local delay = tonumber(jobAttributes[2]) or 0
|
145
|
+
if delay > 0 then
|
146
|
+
local delayedTimestamp = tonumber(timestamp) + delay
|
147
|
+
local score = delayedTimestamp * 0x1000
|
148
|
+
local parentDelayedKey = parentQueueKey .. ":delayed"
|
149
|
+
rcall("ZADD", parentDelayedKey, score, parentId)
|
150
|
+
rcall("XADD", parentQueueKey .. ":events", "*", "event", "delayed",
|
151
|
+
"jobId", parentId, "delay", delayedTimestamp)
|
152
|
+
addDelayMarkerIfNeeded(parentMarkerKey, parentDelayedKey)
|
153
|
+
else
|
154
|
+
if priority == 0 then
|
155
|
+
local parentTarget, _paused =
|
156
|
+
getTargetQueueList(parentMetaKey, parentWaitKey,
|
157
|
+
parentPausedKey)
|
158
|
+
rcall("RPUSH", parentTarget, parentId)
|
159
|
+
rcall("ZADD", parentMarkerKey, 0, "0")
|
160
|
+
else
|
161
|
+
local isPaused = isQueuePaused(parentMetaKey)
|
162
|
+
addJobWithPriority(parentMarkerKey,
|
163
|
+
parentQueueKey .. ":prioritized", priority,
|
164
|
+
parentId, parentQueueKey .. ":pc", isPaused)
|
165
|
+
end
|
166
|
+
rcall("XADD", parentQueueKey .. ":events", "*", "event", "waiting",
|
167
|
+
"jobId", parentId, "prev", "waiting-children")
|
168
|
+
end
|
176
169
|
end
|
177
|
-
end
|
178
170
|
end
|
179
171
|
local function updateParentDepsIfNeeded(parentKey, parentQueueKey, parentDependenciesKey,
|
180
172
|
parentId, jobIdKey, returnvalue, timestamp )
|
@@ -244,8 +236,6 @@ rcall("ZADD", waitChildrenKey, timestamp, jobId)
|
|
244
236
|
rcall("XADD", eventsKey, "MAXLEN", "~", maxEvents, "*", "event",
|
245
237
|
"waiting-children", "jobId", jobId)
|
246
238
|
-- Check if this job is a child of another job, if so add it to the parents dependencies
|
247
|
-
-- TODO: Should not be possible to add a child job to a parent that is not in the "waiting-children" status.
|
248
|
-
-- fail in this case.
|
249
239
|
if parentDependenciesKey ~= nil then
|
250
240
|
rcall("SADD", parentDependenciesKey, jobIdKey)
|
251
241
|
end
|
@@ -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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+Of,CAAC;AACW,QAAA,YAAY,GAAG;IAC1B,IAAI,EAAE,cAAc;IACpB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
|