bullmq 4.14.1 → 4.14.2
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/async-fifo-queue.js +12 -5
- package/dist/cjs/classes/async-fifo-queue.js.map +1 -1
- package/dist/cjs/classes/scripts.js +57 -4
- package/dist/cjs/classes/scripts.js.map +1 -1
- package/dist/cjs/commands/addDelayedJob-7.lua +123 -0
- package/dist/cjs/commands/addParentJob-4.lua +100 -0
- package/dist/cjs/commands/addPrioritizedJob-8.lua +116 -0
- package/dist/cjs/commands/addStandardJob-6.lua +115 -0
- package/dist/cjs/commands/includes/storeJob.lua +30 -0
- package/dist/cjs/commands/includes/updateExistingJobsParent.lua +25 -0
- package/dist/cjs/commands/updateProgress-3.lua +30 -0
- package/dist/cjs/scripts/addDelayedJob-7.js +267 -0
- package/dist/cjs/scripts/addDelayedJob-7.js.map +1 -0
- package/dist/cjs/scripts/addParentJob-4.js +251 -0
- package/dist/cjs/scripts/addParentJob-4.js.map +1 -0
- package/dist/cjs/scripts/addPrioritizedJob-8.js +262 -0
- package/dist/cjs/scripts/addPrioritizedJob-8.js.map +1 -0
- package/dist/cjs/scripts/{addJob-9.js → addStandardJob-6.js} +87 -91
- package/dist/cjs/scripts/addStandardJob-6.js.map +1 -0
- package/dist/cjs/scripts/index.js +4 -1
- package/dist/cjs/scripts/index.js.map +1 -1
- package/dist/cjs/tsconfig-cjs.tsbuildinfo +1 -1
- package/dist/esm/classes/async-fifo-queue.d.ts +13 -1
- package/dist/esm/classes/async-fifo-queue.js +12 -5
- package/dist/esm/classes/async-fifo-queue.js.map +1 -1
- package/dist/esm/classes/job.d.ts +1 -1
- package/dist/esm/classes/scripts.d.ts +3 -0
- package/dist/esm/classes/scripts.js +57 -4
- package/dist/esm/classes/scripts.js.map +1 -1
- package/dist/esm/commands/addDelayedJob-7.lua +123 -0
- package/dist/esm/commands/addParentJob-4.lua +100 -0
- package/dist/esm/commands/addPrioritizedJob-8.lua +116 -0
- package/dist/esm/commands/addStandardJob-6.lua +115 -0
- package/dist/esm/commands/includes/storeJob.lua +30 -0
- package/dist/esm/commands/includes/updateExistingJobsParent.lua +25 -0
- package/dist/esm/commands/updateProgress-3.lua +30 -0
- package/dist/esm/scripts/addDelayedJob-7.d.ts +5 -0
- package/dist/esm/scripts/addDelayedJob-7.js +264 -0
- package/dist/esm/scripts/addDelayedJob-7.js.map +1 -0
- package/dist/esm/scripts/{addJob-9.d.ts → addParentJob-4.d.ts} +1 -1
- package/dist/esm/scripts/addParentJob-4.js +248 -0
- package/dist/esm/scripts/addParentJob-4.js.map +1 -0
- package/dist/esm/scripts/addPrioritizedJob-8.d.ts +5 -0
- package/dist/esm/scripts/addPrioritizedJob-8.js +259 -0
- package/dist/esm/scripts/addPrioritizedJob-8.js.map +1 -0
- package/dist/esm/scripts/addStandardJob-6.d.ts +5 -0
- package/dist/esm/scripts/{addJob-9.js → addStandardJob-6.js} +86 -90
- package/dist/esm/scripts/addStandardJob-6.js.map +1 -0
- package/dist/esm/scripts/index.d.ts +4 -1
- package/dist/esm/scripts/index.js +4 -1
- package/dist/esm/scripts/index.js.map +1 -1
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/dist/cjs/commands/addJob-9.lua +0 -173
- package/dist/cjs/scripts/addJob-9.js.map +0 -1
- package/dist/esm/commands/addJob-9.lua +0 -173
- package/dist/esm/scripts/addJob-9.js.map +0 -1
@@ -1,173 +0,0 @@
|
|
1
|
-
--[[
|
2
|
-
Adds a job to the queue by doing the following:
|
3
|
-
- Increases the job counter if needed.
|
4
|
-
- Creates a new job key with the job data.
|
5
|
-
|
6
|
-
- if delayed:
|
7
|
-
- computes timestamp.
|
8
|
-
- adds to delayed zset.
|
9
|
-
- Emits a global event 'delayed' if the job is delayed.
|
10
|
-
- if not delayed
|
11
|
-
- Adds the jobId to the wait/paused list in one of three ways:
|
12
|
-
- LIFO
|
13
|
-
- FIFO
|
14
|
-
- prioritized.
|
15
|
-
- Adds the job to the "added" list so that workers gets notified.
|
16
|
-
|
17
|
-
Input:
|
18
|
-
KEYS[1] 'wait',
|
19
|
-
KEYS[2] 'paused'
|
20
|
-
KEYS[3] 'meta'
|
21
|
-
KEYS[4] 'id'
|
22
|
-
KEYS[5] 'delayed'
|
23
|
-
KEYS[6] 'prioritized'
|
24
|
-
KEYS[7] 'completed'
|
25
|
-
KEYS[8] events stream key
|
26
|
-
KEYS[9] 'pc' priority counter
|
27
|
-
|
28
|
-
ARGV[1] msgpacked arguments array
|
29
|
-
[1] key prefix,
|
30
|
-
[2] custom id (will not generate one automatically)
|
31
|
-
[3] name
|
32
|
-
[4] timestamp
|
33
|
-
[5] parentKey?
|
34
|
-
[6] waitChildrenKey key.
|
35
|
-
[7] parent dependencies key.
|
36
|
-
[8] parent? {id, queueKey}
|
37
|
-
[9] repeat job key
|
38
|
-
|
39
|
-
ARGV[2] Json stringified job data
|
40
|
-
ARGV[3] msgpacked options
|
41
|
-
|
42
|
-
Output:
|
43
|
-
jobId - OK
|
44
|
-
-5 - Missing parent key
|
45
|
-
]]
|
46
|
-
local jobId
|
47
|
-
local jobIdKey
|
48
|
-
local rcall = redis.call
|
49
|
-
|
50
|
-
local args = cmsgpack.unpack(ARGV[1])
|
51
|
-
|
52
|
-
local data = ARGV[2]
|
53
|
-
local opts = cmsgpack.unpack(ARGV[3])
|
54
|
-
|
55
|
-
local parentKey = args[5]
|
56
|
-
local repeatJobKey = args[9]
|
57
|
-
local parent = args[8]
|
58
|
-
local parentData
|
59
|
-
|
60
|
-
-- Includes
|
61
|
-
--- @include "includes/addDelayMarkerIfNeeded"
|
62
|
-
--- @include "includes/addJobWithPriority"
|
63
|
-
--- @include "includes/getTargetQueueList"
|
64
|
-
--- @include "includes/getNextDelayedTimestamp"
|
65
|
-
--- @include "includes/updateParentDepsIfNeeded"
|
66
|
-
|
67
|
-
if parentKey ~= nil then
|
68
|
-
if rcall("EXISTS", parentKey) ~= 1 then
|
69
|
-
return -5
|
70
|
-
end
|
71
|
-
|
72
|
-
parentData = cjson.encode(parent)
|
73
|
-
end
|
74
|
-
|
75
|
-
local jobCounter = rcall("INCR", KEYS[4])
|
76
|
-
|
77
|
-
local maxEvents = rcall("HGET", KEYS[3], "opts.maxLenEvents") or 10000
|
78
|
-
|
79
|
-
local parentDependenciesKey = args[7]
|
80
|
-
local timestamp = args[4]
|
81
|
-
if args[2] == "" then
|
82
|
-
jobId = jobCounter
|
83
|
-
jobIdKey = args[1] .. jobId
|
84
|
-
else
|
85
|
-
jobId = args[2]
|
86
|
-
jobIdKey = args[1] .. jobId
|
87
|
-
if rcall("EXISTS", jobIdKey) == 1 then
|
88
|
-
if parentKey ~= nil then
|
89
|
-
if rcall("ZSCORE", KEYS[7], jobId) ~= false then
|
90
|
-
local returnvalue = rcall("HGET", jobIdKey, "returnvalue")
|
91
|
-
updateParentDepsIfNeeded(parentKey, parent['queueKey'], parentDependenciesKey,
|
92
|
-
parent['id'], jobIdKey, returnvalue, timestamp)
|
93
|
-
else
|
94
|
-
if parentDependenciesKey ~= nil then
|
95
|
-
rcall("SADD", parentDependenciesKey, jobIdKey)
|
96
|
-
end
|
97
|
-
end
|
98
|
-
rcall("HMSET", jobIdKey, "parentKey", parentKey, "parent", parentData)
|
99
|
-
end
|
100
|
-
rcall("XADD", KEYS[8], "MAXLEN", "~", maxEvents, "*", "event", "duplicated",
|
101
|
-
"jobId", jobId)
|
102
|
-
|
103
|
-
return jobId .. "" -- convert to string
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
-- Store the job.
|
108
|
-
local jsonOpts = cjson.encode(opts)
|
109
|
-
local delay = opts['delay'] or 0
|
110
|
-
local priority = opts['priority'] or 0
|
111
|
-
|
112
|
-
local optionalValues = {}
|
113
|
-
if parentKey ~= nil then
|
114
|
-
table.insert(optionalValues, "parentKey")
|
115
|
-
table.insert(optionalValues, parentKey)
|
116
|
-
table.insert(optionalValues, "parent")
|
117
|
-
table.insert(optionalValues, parentData)
|
118
|
-
end
|
119
|
-
|
120
|
-
if repeatJobKey ~= nil then
|
121
|
-
table.insert(optionalValues, "rjk")
|
122
|
-
table.insert(optionalValues, repeatJobKey)
|
123
|
-
end
|
124
|
-
|
125
|
-
rcall("HMSET", jobIdKey, "name", args[3], "data", ARGV[2], "opts", jsonOpts,
|
126
|
-
"timestamp", timestamp, "delay", delay, "priority", priority, unpack(optionalValues))
|
127
|
-
|
128
|
-
rcall("XADD", KEYS[8], "*", "event", "added", "jobId", jobId, "name", args[3])
|
129
|
-
|
130
|
-
-- Check if job is delayed
|
131
|
-
local delayedTimestamp = (delay > 0 and (timestamp + delay)) or 0
|
132
|
-
|
133
|
-
-- Check if job is a parent, if so add to the parents set
|
134
|
-
local waitChildrenKey = args[6]
|
135
|
-
if waitChildrenKey ~= nil then
|
136
|
-
rcall("ZADD", waitChildrenKey, timestamp, jobId)
|
137
|
-
rcall("XADD", KEYS[8], "MAXLEN", "~", maxEvents, "*", "event", "waiting-children", "jobId", jobId)
|
138
|
-
elseif (delayedTimestamp ~= 0) then
|
139
|
-
local delayedKey = KEYS[5]
|
140
|
-
local score = delayedTimestamp * 0x1000 + bit.band(jobCounter, 0xfff)
|
141
|
-
|
142
|
-
rcall("ZADD", delayedKey, score, jobId)
|
143
|
-
rcall("XADD", KEYS[8], "MAXLEN", "~", maxEvents, "*", "event", "delayed", "jobId", jobId,
|
144
|
-
"delay", delayedTimestamp)
|
145
|
-
|
146
|
-
-- If wait list is empty, and this delayed job is the next one to be processed,
|
147
|
-
-- then we need to signal the workers by adding a dummy job (jobId 0:delay) to the wait list.
|
148
|
-
local target = getTargetQueueList(KEYS[3], KEYS[1], KEYS[2])
|
149
|
-
addDelayMarkerIfNeeded(target, delayedKey)
|
150
|
-
else
|
151
|
-
local target, paused = getTargetQueueList(KEYS[3], KEYS[1], KEYS[2])
|
152
|
-
|
153
|
-
-- Standard or priority add
|
154
|
-
if priority == 0 then
|
155
|
-
-- LIFO or FIFO
|
156
|
-
local pushCmd = opts['lifo'] and 'RPUSH' or 'LPUSH'
|
157
|
-
rcall(pushCmd, target, jobId)
|
158
|
-
else
|
159
|
-
addJobWithPriority(KEYS[1], KEYS[6], priority, paused, jobId, KEYS[9])
|
160
|
-
end
|
161
|
-
-- Emit waiting event
|
162
|
-
rcall("XADD", KEYS[8], "MAXLEN", "~", maxEvents, "*", "event", "waiting",
|
163
|
-
"jobId", jobId)
|
164
|
-
end
|
165
|
-
|
166
|
-
-- Check if this job is a child of another job, if so add it to the parents dependencies
|
167
|
-
-- TODO: Should not be possible to add a child job to a parent that is not in the "waiting-children" status.
|
168
|
-
-- fail in this case.
|
169
|
-
if parentDependenciesKey ~= nil then
|
170
|
-
rcall("SADD", parentDependenciesKey, jobIdKey)
|
171
|
-
end
|
172
|
-
|
173
|
-
return jobId .. "" -- convert to string
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"addJob-9.js","sourceRoot":"","sources":["../../../src/scripts/addJob-9.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgQf,CAAC;AACF,MAAM,CAAC,MAAM,MAAM,GAAG;IACpB,IAAI,EAAE,QAAQ;IACd,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
|