bullmq 5.15.0 → 5.17.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.
Files changed (150) hide show
  1. package/dist/cjs/classes/child-pool.js +2 -2
  2. package/dist/cjs/classes/child-pool.js.map +1 -1
  3. package/dist/cjs/classes/job-scheduler.js +140 -0
  4. package/dist/cjs/classes/job-scheduler.js.map +1 -0
  5. package/dist/cjs/classes/job.js +6 -2
  6. package/dist/cjs/classes/job.js.map +1 -1
  7. package/dist/cjs/classes/queue-events.js.map +1 -1
  8. package/dist/cjs/classes/queue-getters.js +10 -0
  9. package/dist/cjs/classes/queue-getters.js.map +1 -1
  10. package/dist/cjs/classes/queue-keys.js +1 -1
  11. package/dist/cjs/classes/queue-keys.js.map +1 -1
  12. package/dist/cjs/classes/queue.js +74 -0
  13. package/dist/cjs/classes/queue.js.map +1 -1
  14. package/dist/cjs/classes/repeat.js +9 -10
  15. package/dist/cjs/classes/repeat.js.map +1 -1
  16. package/dist/cjs/classes/sandbox.js +57 -47
  17. package/dist/cjs/classes/sandbox.js.map +1 -1
  18. package/dist/cjs/classes/scripts.js +46 -40
  19. package/dist/cjs/classes/scripts.js.map +1 -1
  20. package/dist/cjs/classes/worker.js +23 -4
  21. package/dist/cjs/classes/worker.js.map +1 -1
  22. package/dist/cjs/commands/addDelayedJob-6.lua +7 -7
  23. package/dist/cjs/commands/addJobScheduler-2.lua +75 -0
  24. package/dist/cjs/commands/addParentJob-4.lua +7 -7
  25. package/dist/cjs/commands/addPrioritizedJob-8.lua +7 -7
  26. package/dist/cjs/commands/addStandardJob-8.lua +7 -7
  27. package/dist/cjs/commands/{cleanJobsInSet-2.lua → cleanJobsInSet-3.lua} +6 -5
  28. package/dist/cjs/commands/drain-5.lua +41 -0
  29. package/dist/cjs/commands/includes/cleanSet.lua +50 -29
  30. package/dist/cjs/commands/includes/deduplicateJob.lua +25 -0
  31. package/dist/cjs/commands/includes/removeZSetJobs.lua +13 -1
  32. package/dist/cjs/commands/moveStalledJobsToWait-9.lua +2 -4
  33. package/dist/cjs/commands/removeJob-2.lua +17 -9
  34. package/dist/cjs/commands/removeJobScheduler-3.lua +43 -0
  35. package/dist/cjs/enums/error-code.js +1 -0
  36. package/dist/cjs/enums/error-code.js.map +1 -1
  37. package/dist/cjs/scripts/addDelayedJob-6.js +18 -16
  38. package/dist/cjs/scripts/addDelayedJob-6.js.map +1 -1
  39. package/dist/cjs/scripts/addJobScheduler-2.js +223 -0
  40. package/dist/cjs/scripts/addJobScheduler-2.js.map +1 -0
  41. package/dist/cjs/scripts/addParentJob-4.js +18 -16
  42. package/dist/cjs/scripts/addParentJob-4.js.map +1 -1
  43. package/dist/cjs/scripts/addPrioritizedJob-8.js +18 -16
  44. package/dist/cjs/scripts/addPrioritizedJob-8.js.map +1 -1
  45. package/dist/cjs/scripts/addStandardJob-8.js +18 -16
  46. package/dist/cjs/scripts/addStandardJob-8.js.map +1 -1
  47. package/dist/cjs/scripts/{cleanJobsInSet-2.js → cleanJobsInSet-3.js} +57 -35
  48. package/dist/cjs/scripts/{cleanJobsInSet-2.js.map → cleanJobsInSet-3.js.map} +1 -1
  49. package/dist/cjs/scripts/{drain-4.js → drain-5.js} +28 -7
  50. package/dist/cjs/scripts/drain-5.js.map +1 -0
  51. package/dist/cjs/scripts/index.js +4 -2
  52. package/dist/cjs/scripts/index.js.map +1 -1
  53. package/dist/cjs/scripts/moveStalledJobsToWait-9.js +2 -3
  54. package/dist/cjs/scripts/moveStalledJobsToWait-9.js.map +1 -1
  55. package/dist/cjs/scripts/obliterate-2.js +11 -1
  56. package/dist/cjs/scripts/obliterate-2.js.map +1 -1
  57. package/dist/cjs/scripts/removeJob-2.js +16 -9
  58. package/dist/cjs/scripts/removeJob-2.js.map +1 -1
  59. package/dist/cjs/scripts/removeJobScheduler-3.js +49 -0
  60. package/dist/cjs/scripts/removeJobScheduler-3.js.map +1 -0
  61. package/dist/cjs/tsconfig-cjs.tsbuildinfo +1 -1
  62. package/dist/cjs/utils.js +25 -1
  63. package/dist/cjs/utils.js.map +1 -1
  64. package/dist/esm/classes/child-pool.d.ts +1 -1
  65. package/dist/esm/classes/child-pool.js +2 -2
  66. package/dist/esm/classes/child-pool.js.map +1 -1
  67. package/dist/esm/classes/job-scheduler.d.ts +30 -0
  68. package/dist/esm/classes/job-scheduler.js +135 -0
  69. package/dist/esm/classes/job-scheduler.js.map +1 -0
  70. package/dist/esm/classes/job.d.ts +6 -1
  71. package/dist/esm/classes/job.js +7 -3
  72. package/dist/esm/classes/job.js.map +1 -1
  73. package/dist/esm/classes/queue-events.d.ts +10 -0
  74. package/dist/esm/classes/queue-events.js.map +1 -1
  75. package/dist/esm/classes/queue-getters.d.ts +7 -0
  76. package/dist/esm/classes/queue-getters.js +10 -0
  77. package/dist/esm/classes/queue-getters.js.map +1 -1
  78. package/dist/esm/classes/queue-keys.js +1 -1
  79. package/dist/esm/classes/queue-keys.js.map +1 -1
  80. package/dist/esm/classes/queue.d.ts +54 -0
  81. package/dist/esm/classes/queue.js +74 -0
  82. package/dist/esm/classes/queue.js.map +1 -1
  83. package/dist/esm/classes/repeat.js +9 -10
  84. package/dist/esm/classes/repeat.js.map +1 -1
  85. package/dist/esm/classes/sandbox.js +57 -47
  86. package/dist/esm/classes/sandbox.js.map +1 -1
  87. package/dist/esm/classes/scripts.d.ts +3 -7
  88. package/dist/esm/classes/scripts.js +47 -41
  89. package/dist/esm/classes/scripts.js.map +1 -1
  90. package/dist/esm/classes/worker.d.ts +3 -0
  91. package/dist/esm/classes/worker.js +23 -4
  92. package/dist/esm/classes/worker.js.map +1 -1
  93. package/dist/esm/commands/addDelayedJob-6.lua +7 -7
  94. package/dist/esm/commands/addJobScheduler-2.lua +75 -0
  95. package/dist/esm/commands/addParentJob-4.lua +7 -7
  96. package/dist/esm/commands/addPrioritizedJob-8.lua +7 -7
  97. package/dist/esm/commands/addStandardJob-8.lua +7 -7
  98. package/dist/esm/commands/{cleanJobsInSet-2.lua → cleanJobsInSet-3.lua} +6 -5
  99. package/dist/esm/commands/drain-5.lua +41 -0
  100. package/dist/esm/commands/includes/cleanSet.lua +50 -29
  101. package/dist/esm/commands/includes/deduplicateJob.lua +25 -0
  102. package/dist/esm/commands/includes/removeZSetJobs.lua +13 -1
  103. package/dist/esm/commands/moveStalledJobsToWait-9.lua +2 -4
  104. package/dist/esm/commands/removeJob-2.lua +17 -9
  105. package/dist/esm/commands/removeJobScheduler-3.lua +43 -0
  106. package/dist/esm/enums/error-code.d.ts +2 -1
  107. package/dist/esm/enums/error-code.js +1 -0
  108. package/dist/esm/enums/error-code.js.map +1 -1
  109. package/dist/esm/interfaces/job-json.d.ts +1 -0
  110. package/dist/esm/scripts/addDelayedJob-6.js +18 -16
  111. package/dist/esm/scripts/addDelayedJob-6.js.map +1 -1
  112. package/dist/esm/scripts/addJobScheduler-2.d.ts +5 -0
  113. package/dist/esm/scripts/addJobScheduler-2.js +220 -0
  114. package/dist/esm/scripts/addJobScheduler-2.js.map +1 -0
  115. package/dist/esm/scripts/addParentJob-4.js +18 -16
  116. package/dist/esm/scripts/addParentJob-4.js.map +1 -1
  117. package/dist/esm/scripts/addPrioritizedJob-8.js +18 -16
  118. package/dist/esm/scripts/addPrioritizedJob-8.js.map +1 -1
  119. package/dist/esm/scripts/addStandardJob-8.js +18 -16
  120. package/dist/esm/scripts/addStandardJob-8.js.map +1 -1
  121. package/dist/esm/scripts/{cleanJobsInSet-2.js → cleanJobsInSet-3.js} +57 -35
  122. package/dist/esm/scripts/{cleanJobsInSet-2.js.map → cleanJobsInSet-3.js.map} +1 -1
  123. package/dist/esm/scripts/{drain-4.js → drain-5.js} +28 -7
  124. package/dist/esm/scripts/drain-5.js.map +1 -0
  125. package/dist/esm/scripts/index.d.ts +4 -2
  126. package/dist/esm/scripts/index.js +4 -2
  127. package/dist/esm/scripts/index.js.map +1 -1
  128. package/dist/esm/scripts/moveStalledJobsToWait-9.js +2 -3
  129. package/dist/esm/scripts/moveStalledJobsToWait-9.js.map +1 -1
  130. package/dist/esm/scripts/obliterate-2.js +11 -1
  131. package/dist/esm/scripts/obliterate-2.js.map +1 -1
  132. package/dist/esm/scripts/removeJob-2.js +16 -9
  133. package/dist/esm/scripts/removeJob-2.js.map +1 -1
  134. package/dist/esm/scripts/removeJobScheduler-3.d.ts +5 -0
  135. package/dist/esm/scripts/removeJobScheduler-3.js +46 -0
  136. package/dist/esm/scripts/removeJobScheduler-3.js.map +1 -0
  137. package/dist/esm/tsconfig.tsbuildinfo +1 -1
  138. package/dist/esm/types/job-options.d.ts +5 -0
  139. package/dist/esm/utils.d.ts +7 -0
  140. package/dist/esm/utils.js +23 -0
  141. package/dist/esm/utils.js.map +1 -1
  142. package/package.json +1 -1
  143. package/dist/cjs/commands/drain-4.lua +0 -26
  144. package/dist/cjs/commands/includes/debounceJob.lua +0 -23
  145. package/dist/cjs/scripts/drain-4.js.map +0 -1
  146. package/dist/esm/commands/drain-4.lua +0 -26
  147. package/dist/esm/commands/includes/debounceJob.lua +0 -23
  148. package/dist/esm/scripts/drain-4.js.map +0 -1
  149. /package/dist/esm/scripts/{cleanJobsInSet-2.d.ts → cleanJobsInSet-3.d.ts} +0 -0
  150. /package/dist/esm/scripts/{drain-4.d.ts → drain-5.d.ts} +0 -0
@@ -0,0 +1,5 @@
1
+ export declare const addJobScheduler: {
2
+ name: string;
3
+ content: string;
4
+ keys: number;
5
+ };
@@ -0,0 +1,220 @@
1
+ const content = `--[[
2
+ Adds a job scheduler, i.e. a job factory that creates jobs based on a given schedule (repeat options).
3
+ Input:
4
+ KEYS[1] 'repeat' key
5
+ KEYS[2] 'delayed' key
6
+ ARGV[1] next milliseconds
7
+ ARGV[2] msgpacked options
8
+ [1] name
9
+ [2] tz?
10
+ [3] patten?
11
+ [4] endDate?
12
+ [5] every?
13
+ ARGV[3] jobs scheduler id
14
+ ARGV[4] prefix key
15
+ Output:
16
+ repeatableKey - OK
17
+ ]]
18
+ local rcall = redis.call
19
+ local repeatKey = KEYS[1]
20
+ local delayedKey = KEYS[2]
21
+ local nextMillis = ARGV[1]
22
+ local jobSchedulerId = ARGV[3]
23
+ local prefixKey = ARGV[4]
24
+ -- Includes
25
+ --[[
26
+ Function to remove job.
27
+ ]]
28
+ -- Includes
29
+ --[[
30
+ Function to remove debounce key.
31
+ ]]
32
+ local function removeDebounceKey(prefixKey, jobKey)
33
+ local debounceId = rcall("HGET", jobKey, "deid")
34
+ if debounceId then
35
+ local debounceKey = prefixKey .. "de:" .. debounceId
36
+ rcall("DEL", debounceKey)
37
+ end
38
+ end
39
+ --[[
40
+ Function to remove job keys.
41
+ ]]
42
+ local function removeJobKeys(jobKey)
43
+ return rcall("DEL", jobKey, jobKey .. ':logs',
44
+ jobKey .. ':dependencies', jobKey .. ':processed', jobKey .. ':failed')
45
+ end
46
+ --[[
47
+ Check if this job has a parent. If so we will just remove it from
48
+ the parent child list, but if it is the last child we should move the parent to "wait/paused"
49
+ which requires code from "moveToFinished"
50
+ ]]
51
+ -- Includes
52
+ --[[
53
+ Function to add job in target list and add marker if needed.
54
+ ]]
55
+ -- Includes
56
+ --[[
57
+ Add marker if needed when a job is available.
58
+ ]]
59
+ local function addBaseMarkerIfNeeded(markerKey, isPausedOrMaxed)
60
+ if not isPausedOrMaxed then
61
+ rcall("ZADD", markerKey, 0, "0")
62
+ end
63
+ end
64
+ local function addJobInTargetList(targetKey, markerKey, pushCmd, isPausedOrMaxed, jobId)
65
+ rcall(pushCmd, targetKey, jobId)
66
+ addBaseMarkerIfNeeded(markerKey, isPausedOrMaxed)
67
+ end
68
+ --[[
69
+ Functions to destructure job key.
70
+ Just a bit of warning, these functions may be a bit slow and affect performance significantly.
71
+ ]]
72
+ local getJobIdFromKey = function (jobKey)
73
+ return string.match(jobKey, ".*:(.*)")
74
+ end
75
+ local getJobKeyPrefix = function (jobKey, jobId)
76
+ return string.sub(jobKey, 0, #jobKey - #jobId)
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, activeKey, waitKey, pausedKey)
83
+ local queueAttributes = rcall("HMGET", queueMetaKey, "paused", "concurrency")
84
+ if queueAttributes[1] then
85
+ return pausedKey, true
86
+ else
87
+ if queueAttributes[2] then
88
+ local activeCount = rcall("LLEN", activeKey)
89
+ if activeCount >= tonumber(queueAttributes[2]) then
90
+ return waitKey, true
91
+ else
92
+ return waitKey, false
93
+ end
94
+ end
95
+ end
96
+ return waitKey, false
97
+ end
98
+ local function moveParentToWait(parentPrefix, parentId, emitEvent)
99
+ local parentTarget, isPausedOrMaxed = getTargetQueueList(parentPrefix .. "meta", parentPrefix .. "active",
100
+ parentPrefix .. "wait", parentPrefix .. "paused")
101
+ addJobInTargetList(parentTarget, parentPrefix .. "marker", "RPUSH", isPausedOrMaxed, parentId)
102
+ if emitEvent then
103
+ local parentEventStream = parentPrefix .. "events"
104
+ rcall("XADD", parentEventStream, "*", "event", "waiting", "jobId", parentId, "prev", "waiting-children")
105
+ end
106
+ end
107
+ local function removeParentDependencyKey(jobKey, hard, parentKey, baseKey, debounceId)
108
+ if parentKey then
109
+ local parentDependenciesKey = parentKey .. ":dependencies"
110
+ local result = rcall("SREM", parentDependenciesKey, jobKey)
111
+ if result > 0 then
112
+ local pendingDependencies = rcall("SCARD", parentDependenciesKey)
113
+ if pendingDependencies == 0 then
114
+ local parentId = getJobIdFromKey(parentKey)
115
+ local parentPrefix = getJobKeyPrefix(parentKey, parentId)
116
+ local numRemovedElements = rcall("ZREM", parentPrefix .. "waiting-children", parentId)
117
+ if numRemovedElements == 1 then
118
+ if hard then -- remove parent in same queue
119
+ if parentPrefix == baseKey then
120
+ removeParentDependencyKey(parentKey, hard, nil, baseKey, nil)
121
+ removeJobKeys(parentKey)
122
+ if debounceId then
123
+ rcall("DEL", parentPrefix .. "de:" .. debounceId)
124
+ end
125
+ else
126
+ moveParentToWait(parentPrefix, parentId)
127
+ end
128
+ else
129
+ moveParentToWait(parentPrefix, parentId, true)
130
+ end
131
+ end
132
+ end
133
+ return true
134
+ end
135
+ else
136
+ local parentAttributes = rcall("HMGET", jobKey, "parentKey", "deid")
137
+ local missedParentKey = parentAttributes[1]
138
+ if( (type(missedParentKey) == "string") and missedParentKey ~= ""
139
+ and (rcall("EXISTS", missedParentKey) == 1)) then
140
+ local parentDependenciesKey = missedParentKey .. ":dependencies"
141
+ local result = rcall("SREM", parentDependenciesKey, jobKey)
142
+ if result > 0 then
143
+ local pendingDependencies = rcall("SCARD", parentDependenciesKey)
144
+ if pendingDependencies == 0 then
145
+ local parentId = getJobIdFromKey(missedParentKey)
146
+ local parentPrefix = getJobKeyPrefix(missedParentKey, parentId)
147
+ local numRemovedElements = rcall("ZREM", parentPrefix .. "waiting-children", parentId)
148
+ if numRemovedElements == 1 then
149
+ if hard then
150
+ if parentPrefix == baseKey then
151
+ removeParentDependencyKey(missedParentKey, hard, nil, baseKey, nil)
152
+ removeJobKeys(missedParentKey)
153
+ if parentAttributes[2] then
154
+ rcall("DEL", parentPrefix .. "de:" .. parentAttributes[2])
155
+ end
156
+ else
157
+ moveParentToWait(parentPrefix, parentId)
158
+ end
159
+ else
160
+ moveParentToWait(parentPrefix, parentId, true)
161
+ end
162
+ end
163
+ end
164
+ return true
165
+ end
166
+ end
167
+ end
168
+ return false
169
+ end
170
+ local function removeJob(jobId, hard, baseKey, shouldRemoveDebounceKey)
171
+ local jobKey = baseKey .. jobId
172
+ removeParentDependencyKey(jobKey, hard, nil, baseKey)
173
+ if shouldRemoveDebounceKey then
174
+ removeDebounceKey(baseKey, jobKey)
175
+ end
176
+ removeJobKeys(jobKey)
177
+ end
178
+ local function storeRepeatableJob(repeatKey, nextMillis, rawOpts)
179
+ rcall("ZADD", repeatKey, nextMillis, jobSchedulerId)
180
+ local opts = cmsgpack.unpack(rawOpts)
181
+ local optionalValues = {}
182
+ if opts['tz'] then
183
+ table.insert(optionalValues, "tz")
184
+ table.insert(optionalValues, opts['tz'])
185
+ end
186
+ if opts['pattern'] then
187
+ table.insert(optionalValues, "pattern")
188
+ table.insert(optionalValues, opts['pattern'])
189
+ end
190
+ if opts['endDate'] then
191
+ table.insert(optionalValues, "endDate")
192
+ table.insert(optionalValues, opts['endDate'])
193
+ end
194
+ if opts['every'] then
195
+ table.insert(optionalValues, "every")
196
+ table.insert(optionalValues, opts['every'])
197
+ end
198
+ rcall("HMSET", repeatKey .. ":" .. jobSchedulerId, "name", opts['name'],
199
+ unpack(optionalValues))
200
+ end
201
+ -- If we are overriding a repeatable job we must delete the delayed job for
202
+ -- the next iteration.
203
+ local prevMillis = rcall("ZSCORE", repeatKey, jobSchedulerId)
204
+ if prevMillis ~= false then
205
+ local delayedJobId = "repeat:" .. jobSchedulerId .. ":" .. prevMillis
206
+ local nextDelayedJobId = repeatKey .. ":" .. jobSchedulerId .. ":" .. nextMillis
207
+ if rcall("ZSCORE", delayedKey, delayedJobId) ~= false
208
+ and rcall("EXISTS", nextDelayedJobId) ~= 1 then
209
+ removeJob(delayedJobId, true, prefixKey, true --[[remove debounce key]])
210
+ rcall("ZREM", delayedKey, delayedJobId)
211
+ end
212
+ end
213
+ return storeRepeatableJob(repeatKey, nextMillis, ARGV[2])
214
+ `;
215
+ export const addJobScheduler = {
216
+ name: 'addJobScheduler',
217
+ content,
218
+ keys: 2,
219
+ };
220
+ //# sourceMappingURL=addJobScheduler-2.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"addJobScheduler-2.js","sourceRoot":"","sources":["../../../src/scripts/addJobScheduler-2.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAqNf,CAAC;AACF,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,IAAI,EAAE,iBAAiB;IACvB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
@@ -18,7 +18,7 @@ const content = `--[[
18
18
  [7] parent dependencies key.
19
19
  [8] parent? {id, queueKey}
20
20
  [9] repeat job key
21
- [10] debounce key
21
+ [10] deduplication key
22
22
  ARGV[2] Json stringified job data
23
23
  ARGV[3] msgpacked options
24
24
  Output:
@@ -38,26 +38,28 @@ local opts = cmsgpack.unpack(ARGV[3])
38
38
  local parentKey = args[5]
39
39
  local parent = args[8]
40
40
  local repeatJobKey = args[9]
41
- local debounceKey = args[10]
41
+ local deduplicationKey = args[10]
42
42
  local parentData
43
43
  -- Includes
44
44
  --[[
45
45
  Function to debounce a job.
46
46
  ]]
47
- local function debounceJob(prefixKey, debounceOpts, jobId, debounceKey, eventsKey, maxEvents)
48
- local debounceId = debounceOpts and debounceOpts['id']
49
- if debounceId then
50
- local ttl = debounceOpts['ttl']
51
- local debounceKeyExists
47
+ local function deduplicateJob(prefixKey, deduplicationOpts, jobId, deduplicationKey, eventsKey, maxEvents)
48
+ local deduplicationId = deduplicationOpts and deduplicationOpts['id']
49
+ if deduplicationId then
50
+ local ttl = deduplicationOpts['ttl']
51
+ local deduplicationKeyExists
52
52
  if ttl then
53
- debounceKeyExists = not rcall('SET', debounceKey, jobId, 'PX', ttl, 'NX')
53
+ deduplicationKeyExists = not rcall('SET', deduplicationKey, jobId, 'PX', ttl, 'NX')
54
54
  else
55
- debounceKeyExists = not rcall('SET', debounceKey, jobId, 'NX')
55
+ deduplicationKeyExists = not rcall('SET', deduplicationKey, jobId, 'NX')
56
56
  end
57
- if debounceKeyExists then
58
- local currentDebounceJobId = rcall('GET', debounceKey)
57
+ if deduplicationKeyExists then
58
+ local currentDebounceJobId = rcall('GET', deduplicationKey)
59
59
  rcall("XADD", eventsKey, "MAXLEN", "~", maxEvents, "*", "event",
60
- "debounced", "jobId", currentDebounceJobId, "debounceId", debounceId)
60
+ "debounced", "jobId", currentDebounceJobId, "debounceId", deduplicationId)
61
+ rcall("XADD", eventsKey, "MAXLEN", "~", maxEvents, "*", "event",
62
+ "deduplicated", "jobId", currentDebounceJobId, "deduplicationId", deduplicationId)
61
63
  return currentDebounceJobId
62
64
  end
63
65
  end
@@ -309,10 +311,10 @@ else
309
311
  maxEvents, timestamp)
310
312
  end
311
313
  end
312
- local debouncedJobId = debounceJob(args[1], opts['de'],
313
- jobId, debounceKey, eventsKey, maxEvents)
314
- if debouncedJobId then
315
- return debouncedJobId
314
+ local deduplicationJobId = deduplicateJob(args[1], opts['de'],
315
+ jobId, deduplicationKey, eventsKey, maxEvents)
316
+ if deduplicationJobId then
317
+ return deduplicationJobId
316
318
  end
317
319
  -- Store the job.
318
320
  storeJob(eventsKey, jobIdKey, jobId, args[3], ARGV[2], opts, timestamp,
@@ -1 +1 @@
1
- {"version":3,"file":"addParentJob-4.js","sourceRoot":"","sources":["../../../src/scripts/addParentJob-4.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwUf,CAAC;AACF,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,IAAI,EAAE,cAAc;IACpB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
1
+ {"version":3,"file":"addParentJob-4.js","sourceRoot":"","sources":["../../../src/scripts/addParentJob-4.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA0Uf,CAAC;AACF,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,IAAI,EAAE,cAAc;IACpB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
@@ -22,7 +22,7 @@ const content = `--[[
22
22
  [7] parent dependencies key.
23
23
  [8] parent? {id, queueKey}
24
24
  [9] repeat job key
25
- [10] debounce key
25
+ [10] deduplication key
26
26
  ARGV[2] Json stringified job data
27
27
  ARGV[3] msgpacked options
28
28
  Output:
@@ -45,7 +45,7 @@ local opts = cmsgpack.unpack(ARGV[3])
45
45
  local parentKey = args[5]
46
46
  local parent = args[8]
47
47
  local repeatJobKey = args[9]
48
- local debounceKey = args[10]
48
+ local deduplicationKey = args[10]
49
49
  local parentData
50
50
  -- Includes
51
51
  --[[
@@ -70,20 +70,22 @@ end
70
70
  --[[
71
71
  Function to debounce a job.
72
72
  ]]
73
- local function debounceJob(prefixKey, debounceOpts, jobId, debounceKey, eventsKey, maxEvents)
74
- local debounceId = debounceOpts and debounceOpts['id']
75
- if debounceId then
76
- local ttl = debounceOpts['ttl']
77
- local debounceKeyExists
73
+ local function deduplicateJob(prefixKey, deduplicationOpts, jobId, deduplicationKey, eventsKey, maxEvents)
74
+ local deduplicationId = deduplicationOpts and deduplicationOpts['id']
75
+ if deduplicationId then
76
+ local ttl = deduplicationOpts['ttl']
77
+ local deduplicationKeyExists
78
78
  if ttl then
79
- debounceKeyExists = not rcall('SET', debounceKey, jobId, 'PX', ttl, 'NX')
79
+ deduplicationKeyExists = not rcall('SET', deduplicationKey, jobId, 'PX', ttl, 'NX')
80
80
  else
81
- debounceKeyExists = not rcall('SET', debounceKey, jobId, 'NX')
81
+ deduplicationKeyExists = not rcall('SET', deduplicationKey, jobId, 'NX')
82
82
  end
83
- if debounceKeyExists then
84
- local currentDebounceJobId = rcall('GET', debounceKey)
83
+ if deduplicationKeyExists then
84
+ local currentDebounceJobId = rcall('GET', deduplicationKey)
85
85
  rcall("XADD", eventsKey, "MAXLEN", "~", maxEvents, "*", "event",
86
- "debounced", "jobId", currentDebounceJobId, "debounceId", debounceId)
86
+ "debounced", "jobId", currentDebounceJobId, "debounceId", deduplicationId)
87
+ rcall("XADD", eventsKey, "MAXLEN", "~", maxEvents, "*", "event",
88
+ "deduplicated", "jobId", currentDebounceJobId, "deduplicationId", deduplicationId)
87
89
  return currentDebounceJobId
88
90
  end
89
91
  end
@@ -316,10 +318,10 @@ else
316
318
  maxEvents, timestamp)
317
319
  end
318
320
  end
319
- local debouncedJobId = debounceJob(args[1], opts['de'],
320
- jobId, debounceKey, eventsKey, maxEvents)
321
- if debouncedJobId then
322
- return debouncedJobId
321
+ local deduplicationJobId = deduplicateJob(args[1], opts['de'],
322
+ jobId, deduplicationKey, eventsKey, maxEvents)
323
+ if deduplicationJobId then
324
+ return deduplicationJobId
323
325
  end
324
326
  -- Store the job.
325
327
  local delay, priority = storeJob(eventsKey, jobIdKey, jobId, args[3], ARGV[2],
@@ -1 +1 @@
1
- {"version":3,"file":"addPrioritizedJob-8.js","sourceRoot":"","sources":["../../../src/scripts/addPrioritizedJob-8.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkVf,CAAC;AACF,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,IAAI,EAAE,mBAAmB;IACzB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
1
+ {"version":3,"file":"addPrioritizedJob-8.js","sourceRoot":"","sources":["../../../src/scripts/addPrioritizedJob-8.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAoVf,CAAC;AACF,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,IAAI,EAAE,mBAAmB;IACzB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
@@ -31,7 +31,7 @@ const content = `--[[
31
31
  [7] parent dependencies key.
32
32
  [8] parent? {id, queueKey}
33
33
  [9] repeat job key
34
- [10] debounce key
34
+ [10] deduplication key
35
35
  ARGV[2] Json stringified job data
36
36
  ARGV[3] msgpacked options
37
37
  Output:
@@ -48,7 +48,7 @@ local opts = cmsgpack.unpack(ARGV[3])
48
48
  local parentKey = args[5]
49
49
  local parent = args[8]
50
50
  local repeatJobKey = args[9]
51
- local debounceKey = args[10]
51
+ local deduplicationKey = args[10]
52
52
  local parentData
53
53
  -- Includes
54
54
  --[[
@@ -70,20 +70,22 @@ end
70
70
  --[[
71
71
  Function to debounce a job.
72
72
  ]]
73
- local function debounceJob(prefixKey, debounceOpts, jobId, debounceKey, eventsKey, maxEvents)
74
- local debounceId = debounceOpts and debounceOpts['id']
75
- if debounceId then
76
- local ttl = debounceOpts['ttl']
77
- local debounceKeyExists
73
+ local function deduplicateJob(prefixKey, deduplicationOpts, jobId, deduplicationKey, eventsKey, maxEvents)
74
+ local deduplicationId = deduplicationOpts and deduplicationOpts['id']
75
+ if deduplicationId then
76
+ local ttl = deduplicationOpts['ttl']
77
+ local deduplicationKeyExists
78
78
  if ttl then
79
- debounceKeyExists = not rcall('SET', debounceKey, jobId, 'PX', ttl, 'NX')
79
+ deduplicationKeyExists = not rcall('SET', deduplicationKey, jobId, 'PX', ttl, 'NX')
80
80
  else
81
- debounceKeyExists = not rcall('SET', debounceKey, jobId, 'NX')
81
+ deduplicationKeyExists = not rcall('SET', deduplicationKey, jobId, 'NX')
82
82
  end
83
- if debounceKeyExists then
84
- local currentDebounceJobId = rcall('GET', debounceKey)
83
+ if deduplicationKeyExists then
84
+ local currentDebounceJobId = rcall('GET', deduplicationKey)
85
85
  rcall("XADD", eventsKey, "MAXLEN", "~", maxEvents, "*", "event",
86
- "debounced", "jobId", currentDebounceJobId, "debounceId", debounceId)
86
+ "debounced", "jobId", currentDebounceJobId, "debounceId", deduplicationId)
87
+ rcall("XADD", eventsKey, "MAXLEN", "~", maxEvents, "*", "event",
88
+ "deduplicated", "jobId", currentDebounceJobId, "deduplicationId", deduplicationId)
87
89
  return currentDebounceJobId
88
90
  end
89
91
  end
@@ -320,10 +322,10 @@ else
320
322
  maxEvents, timestamp)
321
323
  end
322
324
  end
323
- local debouncedJobId = debounceJob(args[1], opts['de'],
324
- jobId, debounceKey, eventsKey, maxEvents)
325
- if debouncedJobId then
326
- return debouncedJobId
325
+ local deduplicationJobId = deduplicateJob(args[1], opts['de'],
326
+ jobId, deduplicationKey, eventsKey, maxEvents)
327
+ if deduplicationJobId then
328
+ return deduplicationJobId
327
329
  end
328
330
  -- Store the job.
329
331
  storeJob(eventsKey, jobIdKey, jobId, args[3], ARGV[2], opts, timestamp,
@@ -1 +1 @@
1
- {"version":3,"file":"addStandardJob-8.js","sourceRoot":"","sources":["../../../src/scripts/addStandardJob-8.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAsVf,CAAC;AACF,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,IAAI,EAAE,gBAAgB;IACtB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
1
+ {"version":3,"file":"addStandardJob-8.js","sourceRoot":"","sources":["../../../src/scripts/addStandardJob-8.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwVf,CAAC;AACF,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,IAAI,EAAE,gBAAgB;IACtB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
@@ -3,6 +3,7 @@ const content = `--[[
3
3
  Input:
4
4
  KEYS[1] set key,
5
5
  KEYS[2] events stream key
6
+ KEYS[3] job schedulers key
6
7
  ARGV[1] jobKey prefix
7
8
  ARGV[2] timestamp
8
9
  ARGV[3] limit the number of jobs to be removed. 0 is unlimited
@@ -234,7 +235,7 @@ end
234
235
  --[[
235
236
  Function to clean job set.
236
237
  Returns jobIds and deleted count number.
237
- ]]
238
+ ]]
238
239
  -- Includes
239
240
  --[[
240
241
  Function to loop in batches.
@@ -265,54 +266,75 @@ local function getJobsInZset(zsetKey, rangeEnd, limit)
265
266
  return rcall("ZRANGEBYSCORE", zsetKey, 0, rangeEnd)
266
267
  end
267
268
  end
268
- local function cleanSet(setKey, jobKeyPrefix, rangeEnd, timestamp, limit, attributes, isFinished)
269
- local jobs = getJobsInZset(setKey, rangeEnd, limit)
270
- local deleted = {}
271
- local deletedCount = 0
272
- local jobTS
273
- for i, job in ipairs(jobs) do
274
- if limit > 0 and deletedCount >= limit then
275
- break
269
+ local function isJobSchedulerJob(jobId, jobSchedulersKey)
270
+ if jobSchedulersKey then
271
+ local jobSchedulerId = jobId:match("repeat:(.*):%d+")
272
+ if jobSchedulerId then
273
+ return rcall("ZSCORE", jobSchedulersKey, jobSchedulerId)
274
+ end
276
275
  end
277
- local jobKey = jobKeyPrefix .. job
278
- if isFinished then
279
- removeJob(job, true, jobKeyPrefix, true --[[remove debounce key]])
280
- deletedCount = deletedCount + 1
281
- table.insert(deleted, job)
282
- else
283
- -- * finishedOn says when the job was completed, but it isn't set unless the job has actually completed
284
- jobTS = getTimestamp(jobKey, attributes)
285
- if (not jobTS or jobTS <= timestamp) then
286
- removeJob(job, true, jobKeyPrefix, true --[[remove debounce key]])
287
- deletedCount = deletedCount + 1
288
- table.insert(deleted, job)
289
- end
276
+ return false
277
+ end
278
+ local function cleanSet(
279
+ setKey,
280
+ jobKeyPrefix,
281
+ rangeEnd,
282
+ timestamp,
283
+ limit,
284
+ attributes,
285
+ isFinished,
286
+ jobSchedulersKey)
287
+ local jobs = getJobsInZset(setKey, rangeEnd, limit)
288
+ local deleted = {}
289
+ local deletedCount = 0
290
+ local jobTS
291
+ for i, job in ipairs(jobs) do
292
+ if limit > 0 and deletedCount >= limit then
293
+ break
294
+ end
295
+ -- Extract a Job Scheduler Id from jobId ("repeat:job-scheduler-id:millis")
296
+ -- and check if it is in the scheduled jobs
297
+ if not isJobSchedulerJob(job, jobSchedulersKey) then
298
+ local jobKey = jobKeyPrefix .. job
299
+ if isFinished then
300
+ removeJob(job, true, jobKeyPrefix, true --[[remove debounce key]] )
301
+ deletedCount = deletedCount + 1
302
+ table.insert(deleted, job)
303
+ else
304
+ -- * finishedOn says when the job was completed, but it isn't set unless the job has actually completed
305
+ jobTS = getTimestamp(jobKey, attributes)
306
+ if (not jobTS or jobTS <= timestamp) then
307
+ removeJob(job, true, jobKeyPrefix, true --[[remove debounce key]] )
308
+ deletedCount = deletedCount + 1
309
+ table.insert(deleted, job)
310
+ end
311
+ end
312
+ end
290
313
  end
291
- end
292
- if(#deleted > 0) then
293
- for from, to in batches(#deleted, 7000) do
294
- rcall("ZREM", setKey, unpack(deleted, from, to))
314
+ if (#deleted > 0) then
315
+ for from, to in batches(#deleted, 7000) do
316
+ rcall("ZREM", setKey, unpack(deleted, from, to))
317
+ end
295
318
  end
296
- end
297
- return {deleted, deletedCount}
319
+ return {deleted, deletedCount}
298
320
  end
299
321
  local result
300
322
  if ARGV[4] == "active" then
301
- result = cleanList(KEYS[1], ARGV[1], rangeStart, rangeEnd, ARGV[2], false)
323
+ result = cleanList(KEYS[1], ARGV[1], rangeStart, rangeEnd, ARGV[2], false --[[ hasFinished ]])
302
324
  elseif ARGV[4] == "delayed" then
303
325
  rangeEnd = "+inf"
304
326
  result = cleanSet(KEYS[1], ARGV[1], rangeEnd, ARGV[2], limit,
305
- {"processedOn", "timestamp"}, false)
327
+ {"processedOn", "timestamp"}, false --[[ hasFinished ]], KEYS[3])
306
328
  elseif ARGV[4] == "prioritized" then
307
329
  rangeEnd = "+inf"
308
330
  result = cleanSet(KEYS[1], ARGV[1], rangeEnd, ARGV[2], limit,
309
- {"timestamp"}, false)
331
+ {"timestamp"}, false --[[ hasFinished ]])
310
332
  elseif ARGV[4] == "wait" or ARGV[4] == "paused" then
311
- result = cleanList(KEYS[1], ARGV[1], rangeStart, rangeEnd, ARGV[2], true)
333
+ result = cleanList(KEYS[1], ARGV[1], rangeStart, rangeEnd, ARGV[2], true --[[ hasFinished ]])
312
334
  else
313
335
  rangeEnd = ARGV[2]
314
336
  result = cleanSet(KEYS[1], ARGV[1], rangeEnd, ARGV[2], limit,
315
- {"finishedOn"}, true)
337
+ {"finishedOn"}, true --[[ hasFinished ]])
316
338
  end
317
339
  rcall("XADD", KEYS[2], "*", "event", "cleaned", "count", result[2])
318
340
  return result[1]
@@ -320,6 +342,6 @@ return result[1]
320
342
  export const cleanJobsInSet = {
321
343
  name: 'cleanJobsInSet',
322
344
  content,
323
- keys: 2,
345
+ keys: 3,
324
346
  };
325
- //# sourceMappingURL=cleanJobsInSet-2.js.map
347
+ //# sourceMappingURL=cleanJobsInSet-3.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"cleanJobsInSet-2.js","sourceRoot":"","sources":["../../../src/scripts/cleanJobsInSet-2.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8Tf,CAAC;AACF,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,IAAI,EAAE,gBAAgB;IACtB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
1
+ {"version":3,"file":"cleanJobsInSet-3.js","sourceRoot":"","sources":["../../../src/scripts/cleanJobsInSet-3.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAoVf,CAAC;AACF,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,IAAI,EAAE,gBAAgB;IACtB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
@@ -6,6 +6,7 @@ const content = `--[[
6
6
  KEYS[2] 'paused'
7
7
  KEYS[3] 'delayed'
8
8
  KEYS[4] 'prioritized'
9
+ KEYS[5] 'jobschedulers' (repeat)
9
10
  ARGV[1] queue key prefix
10
11
  ]]
11
12
  local rcall = redis.call
@@ -209,8 +210,18 @@ end
209
210
  local function getZSetItems(keyName, max)
210
211
  return rcall('ZRANGE', keyName, 0, max - 1)
211
212
  end
212
- local function removeZSetJobs(keyName, hard, baseKey, max)
213
+ local function removeZSetJobs(keyName, hard, baseKey, max, jobsToIgnore)
213
214
  local jobs = getZSetItems(keyName, max)
215
+ -- filter out jobs to ignore
216
+ if jobsToIgnore then
217
+ local filteredJobs = {}
218
+ for i = 1, #jobs do
219
+ if not jobsToIgnore[jobs[i]] then
220
+ table.insert(filteredJobs, jobs[i])
221
+ end
222
+ end
223
+ jobs = filteredJobs
224
+ end
214
225
  local count = removeJobs(jobs, hard, baseKey, max)
215
226
  if(#jobs > 0) then
216
227
  for from, to in batches(#jobs, 7000) do
@@ -219,16 +230,26 @@ local function removeZSetJobs(keyName, hard, baseKey, max)
219
230
  end
220
231
  return count
221
232
  end
222
- removeListJobs(KEYS[1], true, queueBaseKey, 0) --wait
223
- removeListJobs(KEYS[2], true, queueBaseKey, 0) --paused
233
+ removeListJobs(KEYS[1], true, queueBaseKey, 0) -- wait
234
+ removeListJobs(KEYS[2], true, queueBaseKey, 0) -- paused
224
235
  if KEYS[3] ~= "" then
225
- removeZSetJobs(KEYS[3], true, queueBaseKey, 0) --delayed
236
+ -- We must not remove delayed jobs if they are associated to a job scheduler.
237
+ local scheduledJobs = {}
238
+ local jobSchedulers = rcall("ZRANGE", KEYS[5], 0, -1, "WITHSCORES")
239
+ -- For every job scheduler, get the current delayed job id.
240
+ for i = 1, #jobSchedulers, 2 do
241
+ local jobSchedulerId = jobSchedulers[i]
242
+ local jobSchedulerMillis = jobSchedulers[i + 1]
243
+ local delayedJobId = "repeat:" .. jobSchedulerId .. ":" .. jobSchedulerMillis
244
+ scheduledJobs[delayedJobId] = true
245
+ end
246
+ removeZSetJobs(KEYS[3], true, queueBaseKey, 0, scheduledJobs) -- delayed
226
247
  end
227
- removeZSetJobs(KEYS[4], true, queueBaseKey, 0) --prioritized
248
+ removeZSetJobs(KEYS[4], true, queueBaseKey, 0) -- prioritized
228
249
  `;
229
250
  export const drain = {
230
251
  name: 'drain',
231
252
  content,
232
- keys: 4,
253
+ keys: 5,
233
254
  };
234
- //# sourceMappingURL=drain-4.js.map
255
+ //# sourceMappingURL=drain-5.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"drain-5.js","sourceRoot":"","sources":["../../../src/scripts/drain-5.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwPf,CAAC;AACF,MAAM,CAAC,MAAM,KAAK,GAAG;IACnB,IAAI,EAAE,OAAO;IACb,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}