bullmq 3.13.3 → 3.14.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/job.js +1 -1
- package/dist/cjs/classes/scripts.js +5 -2
- package/dist/cjs/classes/scripts.js.map +1 -1
- package/dist/cjs/classes/worker.js +2 -9
- package/dist/cjs/classes/worker.js.map +1 -1
- package/dist/cjs/commands/addJob-8.lua +2 -2
- package/dist/cjs/commands/changeDelay-3.lua +2 -3
- package/dist/cjs/commands/getRanges-1.lua +1 -1
- package/dist/cjs/commands/includes/cleanSet.lua +2 -2
- package/dist/cjs/commands/includes/getRateLimitTTL.lua +1 -1
- package/dist/cjs/commands/includes/updateParentDepsIfNeeded.lua +0 -1
- package/dist/cjs/commands/isFinished-3.lua +3 -3
- package/dist/cjs/commands/{moveJobFromActiveToWait-7.lua → moveJobFromActiveToWait-8.lua} +9 -6
- package/dist/cjs/commands/moveToActive-9.lua +46 -44
- package/dist/cjs/commands/moveToDelayed-8.lua +22 -23
- package/dist/cjs/commands/pause-4.lua +8 -8
- package/dist/cjs/commands/promote-6.lua +7 -3
- package/dist/cjs/commands/removeRepeatable-2.lua +3 -0
- package/dist/cjs/commands/reprocessJob-6.lua +1 -1
- package/dist/cjs/commands/retryJob-8.lua +2 -2
- package/dist/cjs/commands/saveStacktrace-1.lua +2 -3
- package/dist/cjs/commands/updateData-1.lua +6 -2
- package/dist/cjs/commands/updateProgress-2.lua +6 -2
- package/dist/cjs/scripts/addJob-8.js +2 -2
- package/dist/cjs/scripts/changeDelay-3.js +2 -2
- package/dist/cjs/scripts/getRanges-1.js +1 -1
- package/dist/cjs/scripts/index.js +1 -2
- package/dist/cjs/scripts/index.js.map +1 -1
- package/dist/cjs/scripts/isFinished-3.js +3 -3
- package/dist/cjs/scripts/{moveJobFromActiveToWait-7.js → moveJobFromActiveToWait-8.js} +10 -7
- package/dist/cjs/scripts/moveJobFromActiveToWait-8.js.map +1 -0
- package/dist/cjs/scripts/moveToActive-9.js +47 -45
- package/dist/cjs/scripts/moveToActive-9.js.map +1 -1
- package/dist/cjs/scripts/moveToDelayed-8.js +22 -22
- package/dist/cjs/scripts/moveToFinished-12.js +1 -1
- package/dist/cjs/scripts/pause-4.js +8 -8
- package/dist/cjs/scripts/promote-6.js +6 -3
- package/dist/cjs/scripts/promote-6.js.map +1 -1
- package/dist/cjs/scripts/removeRepeatable-2.js +2 -0
- package/dist/cjs/scripts/removeRepeatable-2.js.map +1 -1
- package/dist/cjs/scripts/reprocessJob-6.js +1 -1
- package/dist/cjs/scripts/retryJob-8.js +1 -1
- package/dist/cjs/scripts/saveStacktrace-1.js +1 -1
- package/dist/cjs/scripts/updateData-1.js +4 -1
- package/dist/cjs/scripts/updateData-1.js.map +1 -1
- package/dist/cjs/scripts/updateProgress-2.js +3 -0
- package/dist/cjs/scripts/updateProgress-2.js.map +1 -1
- package/dist/cjs/tsconfig-cjs.tsbuildinfo +1 -1
- package/dist/esm/classes/job.js +1 -1
- package/dist/esm/classes/scripts.d.ts +1 -1
- package/dist/esm/classes/scripts.js +5 -2
- package/dist/esm/classes/scripts.js.map +1 -1
- package/dist/esm/classes/worker.d.ts +1 -1
- package/dist/esm/classes/worker.js +2 -9
- package/dist/esm/classes/worker.js.map +1 -1
- package/dist/esm/commands/addJob-8.lua +2 -2
- package/dist/esm/commands/changeDelay-3.lua +2 -3
- package/dist/esm/commands/getRanges-1.lua +1 -1
- package/dist/esm/commands/includes/cleanSet.lua +2 -2
- package/dist/esm/commands/includes/getRateLimitTTL.lua +1 -1
- package/dist/esm/commands/includes/updateParentDepsIfNeeded.lua +0 -1
- package/dist/esm/commands/isFinished-3.lua +3 -3
- package/dist/esm/commands/{moveJobFromActiveToWait-7.lua → moveJobFromActiveToWait-8.lua} +9 -6
- package/dist/esm/commands/moveToActive-9.lua +46 -44
- package/dist/esm/commands/moveToDelayed-8.lua +22 -23
- package/dist/esm/commands/pause-4.lua +8 -8
- package/dist/esm/commands/promote-6.lua +7 -3
- package/dist/esm/commands/removeRepeatable-2.lua +3 -0
- package/dist/esm/commands/reprocessJob-6.lua +1 -1
- package/dist/esm/commands/retryJob-8.lua +2 -2
- package/dist/esm/commands/saveStacktrace-1.lua +2 -3
- package/dist/esm/commands/updateData-1.lua +6 -2
- package/dist/esm/commands/updateProgress-2.lua +6 -2
- package/dist/esm/scripts/addJob-8.js +2 -2
- package/dist/esm/scripts/changeDelay-3.js +2 -2
- package/dist/esm/scripts/getRanges-1.js +1 -1
- package/dist/esm/scripts/index.d.ts +1 -2
- package/dist/esm/scripts/index.js +1 -2
- package/dist/esm/scripts/index.js.map +1 -1
- package/dist/esm/scripts/isFinished-3.js +3 -3
- package/dist/esm/scripts/{moveJobFromActiveToWait-7.js → moveJobFromActiveToWait-8.js} +10 -7
- package/dist/esm/scripts/moveJobFromActiveToWait-8.js.map +1 -0
- package/dist/esm/scripts/moveToActive-9.js +47 -45
- package/dist/esm/scripts/moveToActive-9.js.map +1 -1
- package/dist/esm/scripts/moveToDelayed-8.js +22 -22
- package/dist/esm/scripts/moveToFinished-12.js +1 -1
- package/dist/esm/scripts/pause-4.js +8 -8
- package/dist/esm/scripts/promote-6.js +6 -3
- package/dist/esm/scripts/promote-6.js.map +1 -1
- package/dist/esm/scripts/removeRepeatable-2.js +2 -0
- package/dist/esm/scripts/removeRepeatable-2.js.map +1 -1
- package/dist/esm/scripts/reprocessJob-6.js +1 -1
- package/dist/esm/scripts/retryJob-8.js +1 -1
- package/dist/esm/scripts/saveStacktrace-1.js +1 -1
- package/dist/esm/scripts/updateData-1.js +4 -1
- package/dist/esm/scripts/updateData-1.js.map +1 -1
- package/dist/esm/scripts/updateProgress-2.js +3 -0
- package/dist/esm/scripts/updateProgress-2.js.map +1 -1
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/dist/cjs/commands/takeLock-1.lua +0 -17
- package/dist/cjs/scripts/moveJobFromActiveToWait-7.js.map +0 -1
- package/dist/cjs/scripts/takeLock-1.js +0 -24
- package/dist/cjs/scripts/takeLock-1.js.map +0 -1
- package/dist/esm/commands/takeLock-1.lua +0 -17
- package/dist/esm/scripts/moveJobFromActiveToWait-7.js.map +0 -1
- package/dist/esm/scripts/takeLock-1.d.ts +0 -5
- package/dist/esm/scripts/takeLock-1.js +0 -21
- package/dist/esm/scripts/takeLock-1.js.map +0 -1
- /package/dist/esm/scripts/{moveJobFromActiveToWait-7.d.ts → moveJobFromActiveToWait-8.d.ts} +0 -0
@@ -12,15 +12,15 @@
|
|
12
12
|
0 - Not finished.
|
13
13
|
1 - Completed.
|
14
14
|
2 - Failed.
|
15
|
-
-
|
15
|
+
-1 - Missing job.
|
16
16
|
]]
|
17
17
|
local rcall = redis.call
|
18
18
|
if rcall("EXISTS", KEYS[3]) ~= 1 then
|
19
19
|
if ARGV[2] == "1" then
|
20
20
|
|
21
|
-
return {-
|
21
|
+
return {-1,"Missing key for job " .. KEYS[3] .. ". isFinished"}
|
22
22
|
end
|
23
|
-
return -
|
23
|
+
return -1
|
24
24
|
end
|
25
25
|
|
26
26
|
if rcall("ZSCORE", KEYS[1], ARGV[1]) ~= false then
|
@@ -8,11 +8,11 @@
|
|
8
8
|
KEYS[4] job lock key
|
9
9
|
KEYS[5] paused key
|
10
10
|
KEYS[6] meta key
|
11
|
-
KEYS[7]
|
12
|
-
|
13
|
-
args[1] job id
|
14
|
-
args[2] lock token
|
11
|
+
KEYS[7] limiter key
|
12
|
+
KEYS[8] event key
|
15
13
|
|
14
|
+
ARGV[1] job id
|
15
|
+
ARGV[2] lock token
|
16
16
|
]]
|
17
17
|
local rcall = redis.call
|
18
18
|
|
@@ -24,7 +24,8 @@ local token = ARGV[2]
|
|
24
24
|
local lockKey = KEYS[4]
|
25
25
|
|
26
26
|
local lockToken = rcall("GET", lockKey)
|
27
|
-
|
27
|
+
local pttl = rcall("PTTL", KEYS[7])
|
28
|
+
if lockToken == token and pttl > 0 then
|
28
29
|
local removed = rcall("LREM", KEYS[1], 1, jobId)
|
29
30
|
if (removed > 0) then
|
30
31
|
local target = getTargetQueueList(KEYS[6], KEYS[2], KEYS[5])
|
@@ -34,6 +35,8 @@ if lockToken == token then
|
|
34
35
|
rcall("DEL", lockKey)
|
35
36
|
|
36
37
|
-- Emit waiting event
|
37
|
-
rcall("XADD", KEYS[
|
38
|
+
rcall("XADD", KEYS[8], "*", "event", "waiting", "jobId", jobId)
|
38
39
|
end
|
39
40
|
end
|
41
|
+
|
42
|
+
return pttl
|
@@ -7,29 +7,29 @@
|
|
7
7
|
so that no other worker picks this job again.
|
8
8
|
|
9
9
|
Input:
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
10
|
+
KEYS[1] wait key
|
11
|
+
KEYS[2] active key
|
12
|
+
KEYS[3] priority key
|
13
|
+
KEYS[4] stream events key
|
14
|
+
KEYS[5] stalled key
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
-- Rate limiting
|
17
|
+
KEYS[6] rate limiter key
|
18
|
+
KEYS[7] delayed key
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
-- Promote delayed jobs
|
21
|
+
KEYS[8] paused key
|
22
|
+
KEYS[9] meta key
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
24
|
+
-- Arguments
|
25
|
+
ARGV[1] key prefix
|
26
|
+
ARGV[2] timestamp
|
27
|
+
ARGV[3] optional job ID
|
28
|
+
ARGV[4] opts
|
29
29
|
|
30
|
-
|
31
|
-
|
32
|
-
|
30
|
+
opts - token - lock token
|
31
|
+
opts - lockDuration
|
32
|
+
opts - limiter
|
33
33
|
]]
|
34
34
|
local jobId
|
35
35
|
local rcall = redis.call
|
@@ -45,39 +45,41 @@ promoteDelayedJobs(KEYS[7], KEYS[1], KEYS[3], KEYS[8], KEYS[9], KEYS[4], ARGV[1]
|
|
45
45
|
|
46
46
|
local opts
|
47
47
|
if (ARGV[3] ~= "") then
|
48
|
-
|
49
|
-
|
50
|
-
|
48
|
+
jobId = ARGV[3]
|
49
|
+
-- clean stalled key
|
50
|
+
rcall("SREM", KEYS[5], jobId)
|
51
51
|
else
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
52
|
+
-- Check if we are rate limited first.
|
53
|
+
opts = cmsgpack.unpack(ARGV[4])
|
54
|
+
local pttl = getRateLimitTTL(opts, KEYS[6])
|
55
|
+
if pttl > 0 then
|
56
|
+
return { 0, 0, pttl }
|
57
|
+
end
|
58
58
|
|
59
|
-
|
60
|
-
|
59
|
+
-- no job ID, try non-blocking move from wait to active
|
60
|
+
jobId = rcall("RPOPLPUSH", KEYS[1], KEYS[2])
|
61
61
|
end
|
62
62
|
|
63
63
|
-- If jobId is special ID 0:delay, then there is no job to process
|
64
|
-
if jobId then
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
64
|
+
if jobId then
|
65
|
+
if string.sub(jobId, 1, 2) == "0:" then
|
66
|
+
rcall("LREM", KEYS[2], 1, jobId)
|
67
|
+
-- Move again since we just got the marker job.
|
68
|
+
jobId = rcall("RPOPLPUSH", KEYS[1], KEYS[2])
|
69
69
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
70
|
+
-- Since it is possible that between a call to BRPOPLPUSH and moveToActive
|
71
|
+
-- another script puts a new maker in wait, we need to check again.
|
72
|
+
if jobId and string.sub(jobId, 1, 2) == "0:" then
|
73
|
+
rcall("LREM", KEYS[2], 1, jobId)
|
74
|
+
jobId = rcall("RPOPLPUSH", KEYS[1], KEYS[2])
|
74
75
|
end
|
76
|
+
end
|
75
77
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
78
|
+
if jobId then
|
79
|
+
opts = opts or cmsgpack.unpack(ARGV[4])
|
80
|
+
-- this script is not really moving, it is preparing the job for processing
|
81
|
+
return moveJobFromWaitToActive(KEYS, ARGV[1], jobId, ARGV[2], opts)
|
82
|
+
end
|
81
83
|
end
|
82
84
|
|
83
85
|
-- Return the timestamp for the next delayed job if any.
|
@@ -35,34 +35,33 @@ local rcall = redis.call
|
|
35
35
|
|
36
36
|
local jobKey = KEYS[5]
|
37
37
|
if rcall("EXISTS", jobKey) == 1 then
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
return -2
|
46
|
-
end
|
38
|
+
local delayedKey = KEYS[4]
|
39
|
+
if ARGV[5] ~= "0" then
|
40
|
+
local lockKey = jobKey .. ':lock'
|
41
|
+
if rcall("GET", lockKey) == ARGV[5] then
|
42
|
+
rcall("DEL", lockKey)
|
43
|
+
else
|
44
|
+
return -2
|
47
45
|
end
|
46
|
+
end
|
48
47
|
|
49
|
-
|
50
|
-
|
51
|
-
|
48
|
+
local jobId = ARGV[4]
|
49
|
+
local score = tonumber(ARGV[3])
|
50
|
+
local delayedTimestamp = (score / 0x1000)
|
52
51
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
52
|
+
local numRemovedElements = rcall("LREM", KEYS[2], -1, jobId)
|
53
|
+
if numRemovedElements < 1 then
|
54
|
+
return -3
|
55
|
+
end
|
57
56
|
|
58
|
-
|
59
|
-
|
57
|
+
rcall("ZADD", delayedKey, score, jobId)
|
58
|
+
rcall("XADD", KEYS[6], "*", "event", "delayed", "jobId", jobId, "delay", delayedTimestamp)
|
60
59
|
|
61
|
-
|
62
|
-
|
63
|
-
|
60
|
+
-- Check if we need to push a marker job to wake up sleeping workers.
|
61
|
+
local target = getTargetQueueList(KEYS[8], KEYS[1], KEYS[7])
|
62
|
+
addDelayMarkerIfNeeded(target, delayedKey)
|
64
63
|
|
65
|
-
|
64
|
+
return 0
|
66
65
|
else
|
67
|
-
|
66
|
+
return -1
|
68
67
|
end
|
@@ -1,16 +1,16 @@
|
|
1
1
|
--[[
|
2
2
|
Pauses or resumes a queue globably.
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
Input:
|
5
|
+
KEYS[1] 'wait' or 'paused''
|
6
|
+
KEYS[2] 'paused' or 'wait'
|
7
|
+
KEYS[3] 'meta'
|
8
|
+
KEYS[4] events stream key
|
9
9
|
|
10
|
-
|
10
|
+
ARGV[1] 'paused' or 'resumed'
|
11
11
|
|
12
|
-
|
13
|
-
|
12
|
+
Event:
|
13
|
+
publish paused or resumed event.
|
14
14
|
]]
|
15
15
|
local rcall = redis.call
|
16
16
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
--[[
|
2
2
|
Promotes a job that is currently "delayed" to the "waiting" state
|
3
3
|
|
4
|
-
|
4
|
+
Input:
|
5
5
|
KEYS[1] 'delayed'
|
6
6
|
KEYS[2] 'wait'
|
7
7
|
KEYS[3] 'paused'
|
@@ -12,10 +12,14 @@
|
|
12
12
|
ARGV[1] queue.toKey('')
|
13
13
|
ARGV[2] jobId
|
14
14
|
|
15
|
-
|
15
|
+
Output:
|
16
|
+
0 - OK
|
17
|
+
-3 - Job not in delayed zset.
|
18
|
+
|
19
|
+
Events:
|
16
20
|
'waiting'
|
17
21
|
]]
|
18
|
-
local rcall = redis.call
|
22
|
+
local rcall = redis.call
|
19
23
|
local jobId = ARGV[2]
|
20
24
|
|
21
25
|
-- Includes
|
@@ -50,8 +50,8 @@ if rcall("EXISTS", KEYS[4]) == 1 then
|
|
50
50
|
rcall(ARGV[3], target, ARGV[4])
|
51
51
|
|
52
52
|
-- Emit waiting event
|
53
|
-
rcall("XADD", KEYS[6], "*", "event", "waiting", "jobId", ARGV[4], "prev", "failed")
|
54
|
-
|
53
|
+
rcall("XADD", KEYS[6], "*", "event", "waiting", "jobId", ARGV[4], "prev", "failed")
|
54
|
+
|
55
55
|
return 0
|
56
56
|
else
|
57
57
|
return -1
|
@@ -8,15 +8,14 @@
|
|
8
8
|
ARGV[2] failedReason
|
9
9
|
|
10
10
|
Output:
|
11
|
-
|
11
|
+
0 - OK
|
12
12
|
-1 - Missing key
|
13
13
|
]]
|
14
14
|
local rcall = redis.call
|
15
15
|
|
16
16
|
if rcall("EXISTS", KEYS[1]) == 1 then
|
17
|
-
|
18
17
|
rcall("HMSET", KEYS[1], "stacktrace", ARGV[1], "failedReason", ARGV[2])
|
19
|
-
|
18
|
+
|
20
19
|
return 0
|
21
20
|
else
|
22
21
|
return -1
|
@@ -172,7 +172,7 @@ else
|
|
172
172
|
end
|
173
173
|
rcall("XADD", KEYS[8], "*", "event", "duplicated", "jobId", jobId)
|
174
174
|
return jobId .. "" -- convert to string
|
175
|
-
end
|
175
|
+
end
|
176
176
|
end
|
177
177
|
-- Store the job.
|
178
178
|
local jsonOpts = cjson.encode(opts)
|
@@ -213,7 +213,7 @@ else
|
|
213
213
|
-- Standard or priority add
|
214
214
|
if priority == 0 then
|
215
215
|
-- LIFO or FIFO
|
216
|
-
local pushCmd = opts['lifo'] and 'RPUSH' or 'LPUSH'
|
216
|
+
local pushCmd = opts['lifo'] and 'RPUSH' or 'LPUSH'
|
217
217
|
rcall(pushCmd, target, jobId)
|
218
218
|
else
|
219
219
|
-- Priority add
|
@@ -20,12 +20,12 @@ if rcall("EXISTS", KEYS[2]) == 1 then
|
|
20
20
|
local score = tonumber(ARGV[2])
|
21
21
|
local delayedTimestamp = (score / 0x1000)
|
22
22
|
local numRemovedElements = rcall("ZREM", KEYS[1], jobId)
|
23
|
-
if
|
23
|
+
if numRemovedElements < 1 then
|
24
24
|
return -3
|
25
25
|
end
|
26
26
|
rcall("HSET", KEYS[2], "delay", tonumber(ARGV[1]))
|
27
27
|
rcall("ZADD", KEYS[1], score, jobId)
|
28
|
-
rcall("XADD", KEYS[3], "*", "event", "delayed", "jobId", jobId, "delay", delayedTimestamp)
|
28
|
+
rcall("XADD", KEYS[3], "*", "event", "delayed", "jobId", jobId, "delay", delayedTimestamp)
|
29
29
|
return 0
|
30
30
|
else
|
31
31
|
return -1
|
@@ -9,7 +9,7 @@ export * from './getState-7';
|
|
9
9
|
export * from './getStateV2-7';
|
10
10
|
export * from './isFinished-3';
|
11
11
|
export * from './isJobInList-1';
|
12
|
-
export * from './moveJobFromActiveToWait-
|
12
|
+
export * from './moveJobFromActiveToWait-8';
|
13
13
|
export * from './moveStalledJobsToWait-8';
|
14
14
|
export * from './moveToActive-9';
|
15
15
|
export * from './moveToDelayed-8';
|
@@ -25,6 +25,5 @@ export * from './reprocessJob-6';
|
|
25
25
|
export * from './retryJob-8';
|
26
26
|
export * from './retryJobs-6';
|
27
27
|
export * from './saveStacktrace-1';
|
28
|
-
export * from './takeLock-1';
|
29
28
|
export * from './updateData-1';
|
30
29
|
export * from './updateProgress-2';
|
@@ -9,7 +9,7 @@ export * from './getState-7';
|
|
9
9
|
export * from './getStateV2-7';
|
10
10
|
export * from './isFinished-3';
|
11
11
|
export * from './isJobInList-1';
|
12
|
-
export * from './moveJobFromActiveToWait-
|
12
|
+
export * from './moveJobFromActiveToWait-8';
|
13
13
|
export * from './moveStalledJobsToWait-8';
|
14
14
|
export * from './moveToActive-9';
|
15
15
|
export * from './moveToDelayed-8';
|
@@ -25,7 +25,6 @@ export * from './reprocessJob-6';
|
|
25
25
|
export * from './retryJob-8';
|
26
26
|
export * from './retryJobs-6';
|
27
27
|
export * from './saveStacktrace-1';
|
28
|
-
export * from './takeLock-1';
|
29
28
|
export * from './updateData-1';
|
30
29
|
export * from './updateProgress-2';
|
31
30
|
//# sourceMappingURL=index.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/scripts/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/scripts/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,kBAAkB,CAAC;AACjC,cAAc,mBAAmB,CAAC;AAClC,cAAc,qBAAqB,CAAC;AACpC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,eAAe,CAAC;AAC9B,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oBAAoB,CAAC"}
|
@@ -10,14 +10,14 @@ const content = `--[[
|
|
10
10
|
0 - Not finished.
|
11
11
|
1 - Completed.
|
12
12
|
2 - Failed.
|
13
|
-
-
|
13
|
+
-1 - Missing job.
|
14
14
|
]]
|
15
15
|
local rcall = redis.call
|
16
16
|
if rcall("EXISTS", KEYS[3]) ~= 1 then
|
17
17
|
if ARGV[2] == "1" then
|
18
|
-
return {-
|
18
|
+
return {-1,"Missing key for job " .. KEYS[3] .. ". isFinished"}
|
19
19
|
end
|
20
|
-
return -
|
20
|
+
return -1
|
21
21
|
end
|
22
22
|
if rcall("ZSCORE", KEYS[1], ARGV[1]) ~= false then
|
23
23
|
if ARGV[2] == "1" then
|
@@ -7,9 +7,10 @@ const content = `--[[
|
|
7
7
|
KEYS[4] job lock key
|
8
8
|
KEYS[5] paused key
|
9
9
|
KEYS[6] meta key
|
10
|
-
KEYS[7]
|
11
|
-
|
12
|
-
|
10
|
+
KEYS[7] limiter key
|
11
|
+
KEYS[8] event key
|
12
|
+
ARGV[1] job id
|
13
|
+
ARGV[2] lock token
|
13
14
|
]]
|
14
15
|
local rcall = redis.call
|
15
16
|
-- Includes
|
@@ -28,7 +29,8 @@ local jobId = ARGV[1]
|
|
28
29
|
local token = ARGV[2]
|
29
30
|
local lockKey = KEYS[4]
|
30
31
|
local lockToken = rcall("GET", lockKey)
|
31
|
-
|
32
|
+
local pttl = rcall("PTTL", KEYS[7])
|
33
|
+
if lockToken == token and pttl > 0 then
|
32
34
|
local removed = rcall("LREM", KEYS[1], 1, jobId)
|
33
35
|
if (removed > 0) then
|
34
36
|
local target = getTargetQueueList(KEYS[6], KEYS[2], KEYS[5])
|
@@ -36,13 +38,14 @@ if lockToken == token then
|
|
36
38
|
rcall("RPUSH", target, jobId)
|
37
39
|
rcall("DEL", lockKey)
|
38
40
|
-- Emit waiting event
|
39
|
-
rcall("XADD", KEYS[
|
41
|
+
rcall("XADD", KEYS[8], "*", "event", "waiting", "jobId", jobId)
|
40
42
|
end
|
41
43
|
end
|
44
|
+
return pttl
|
42
45
|
`;
|
43
46
|
export const moveJobFromActiveToWait = {
|
44
47
|
name: 'moveJobFromActiveToWait',
|
45
48
|
content,
|
46
|
-
keys:
|
49
|
+
keys: 8,
|
47
50
|
};
|
48
|
-
//# sourceMappingURL=moveJobFromActiveToWait-
|
51
|
+
//# sourceMappingURL=moveJobFromActiveToWait-8.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"moveJobFromActiveToWait-8.js","sourceRoot":"","sources":["../../../src/scripts/moveJobFromActiveToWait-8.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4Cf,CAAC;AACF,MAAM,CAAC,MAAM,uBAAuB,GAAG;IACrC,IAAI,EAAE,yBAAyB;IAC/B,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
|
@@ -5,25 +5,25 @@ const content = `--[[
|
|
5
5
|
expiration time. The worker is responsible of keeping the lock fresh
|
6
6
|
so that no other worker picks this job again.
|
7
7
|
Input:
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
8
|
+
KEYS[1] wait key
|
9
|
+
KEYS[2] active key
|
10
|
+
KEYS[3] priority key
|
11
|
+
KEYS[4] stream events key
|
12
|
+
KEYS[5] stalled key
|
13
|
+
-- Rate limiting
|
14
|
+
KEYS[6] rate limiter key
|
15
|
+
KEYS[7] delayed key
|
16
|
+
-- Promote delayed jobs
|
17
|
+
KEYS[8] paused key
|
18
|
+
KEYS[9] meta key
|
19
|
+
-- Arguments
|
20
|
+
ARGV[1] key prefix
|
21
|
+
ARGV[2] timestamp
|
22
|
+
ARGV[3] optional job ID
|
23
|
+
ARGV[4] opts
|
24
|
+
opts - token - lock token
|
25
|
+
opts - lockDuration
|
26
|
+
opts - limiter
|
27
27
|
]]
|
28
28
|
local jobId
|
29
29
|
local rcall = redis.call
|
@@ -157,7 +157,7 @@ local function getRateLimitTTL(opts, limiterKey)
|
|
157
157
|
if jobCounter ~= nil and jobCounter >= maxJobs then
|
158
158
|
local pttl = rcall("PTTL", limiterKey)
|
159
159
|
if pttl > 0 then
|
160
|
-
return pttl
|
160
|
+
return pttl
|
161
161
|
end
|
162
162
|
end
|
163
163
|
end
|
@@ -167,35 +167,37 @@ end
|
|
167
167
|
promoteDelayedJobs(KEYS[7], KEYS[1], KEYS[3], KEYS[8], KEYS[9], KEYS[4], ARGV[1], ARGV[2])
|
168
168
|
local opts
|
169
169
|
if (ARGV[3] ~= "") then
|
170
|
-
|
171
|
-
|
172
|
-
|
170
|
+
jobId = ARGV[3]
|
171
|
+
-- clean stalled key
|
172
|
+
rcall("SREM", KEYS[5], jobId)
|
173
173
|
else
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
174
|
+
-- Check if we are rate limited first.
|
175
|
+
opts = cmsgpack.unpack(ARGV[4])
|
176
|
+
local pttl = getRateLimitTTL(opts, KEYS[6])
|
177
|
+
if pttl > 0 then
|
178
|
+
return { 0, 0, pttl }
|
179
|
+
end
|
180
|
+
-- no job ID, try non-blocking move from wait to active
|
181
|
+
jobId = rcall("RPOPLPUSH", KEYS[1], KEYS[2])
|
182
182
|
end
|
183
183
|
-- If jobId is special ID 0:delay, then there is no job to process
|
184
|
-
if jobId then
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
if jobId then
|
195
|
-
opts = opts or cmsgpack.unpack(ARGV[4])
|
196
|
-
-- this script is not really moving, it is preparing the job for processing
|
197
|
-
return moveJobFromWaitToActive(KEYS, ARGV[1], jobId, ARGV[2], opts)
|
184
|
+
if jobId then
|
185
|
+
if string.sub(jobId, 1, 2) == "0:" then
|
186
|
+
rcall("LREM", KEYS[2], 1, jobId)
|
187
|
+
-- Move again since we just got the marker job.
|
188
|
+
jobId = rcall("RPOPLPUSH", KEYS[1], KEYS[2])
|
189
|
+
-- Since it is possible that between a call to BRPOPLPUSH and moveToActive
|
190
|
+
-- another script puts a new maker in wait, we need to check again.
|
191
|
+
if jobId and string.sub(jobId, 1, 2) == "0:" then
|
192
|
+
rcall("LREM", KEYS[2], 1, jobId)
|
193
|
+
jobId = rcall("RPOPLPUSH", KEYS[1], KEYS[2])
|
198
194
|
end
|
195
|
+
end
|
196
|
+
if jobId then
|
197
|
+
opts = opts or cmsgpack.unpack(ARGV[4])
|
198
|
+
-- this script is not really moving, it is preparing the job for processing
|
199
|
+
return moveJobFromWaitToActive(KEYS, ARGV[1], jobId, ARGV[2], opts)
|
200
|
+
end
|
199
201
|
end
|
200
202
|
-- Return the timestamp for the next delayed job if any.
|
201
203
|
local nextTimestamp = getNextDelayedTimestamp(KEYS[7])
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"moveToActive-9.js","sourceRoot":"","sources":["../../../src/scripts/moveToActive-9.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG
|
1
|
+
{"version":3,"file":"moveToActive-9.js","sourceRoot":"","sources":["../../../src/scripts/moveToActive-9.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8Mf,CAAC;AACF,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,IAAI,EAAE,cAAc;IACpB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
|