bullmq 2.2.0 → 2.2.1

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 (234) hide show
  1. package/dist/cjs/classes/job.d.ts +1 -1
  2. package/dist/cjs/classes/redis-connection.d.ts +6 -2
  3. package/dist/cjs/classes/redis-connection.js +11 -5
  4. package/dist/cjs/classes/redis-connection.js.map +1 -1
  5. package/dist/cjs/scripts/addJob-8.d.ts +5 -0
  6. package/dist/{esm/commands/addJob-8.lua → cjs/scripts/addJob-8.js} +83 -31
  7. package/dist/cjs/scripts/addJob-8.js.map +1 -0
  8. package/dist/cjs/scripts/changeDelay-4.d.ts +5 -0
  9. package/dist/cjs/{commands/changeDelay-4.lua → scripts/changeDelay-4.js} +11 -11
  10. package/dist/cjs/scripts/changeDelay-4.js.map +1 -0
  11. package/dist/cjs/scripts/cleanJobsInSet-2.d.ts +5 -0
  12. package/dist/cjs/scripts/cleanJobsInSet-2.js +264 -0
  13. package/dist/cjs/scripts/cleanJobsInSet-2.js.map +1 -0
  14. package/dist/cjs/scripts/drain-4.d.ts +5 -0
  15. package/dist/cjs/{commands/includes/removeParentDependencyKey.lua → scripts/drain-4.js} +110 -10
  16. package/dist/cjs/scripts/drain-4.js.map +1 -0
  17. package/dist/cjs/scripts/extendLock-2.d.ts +5 -0
  18. package/dist/{esm/commands/extendLock-2.lua → cjs/scripts/extendLock-2.js} +11 -4
  19. package/dist/cjs/scripts/extendLock-2.js.map +1 -0
  20. package/dist/cjs/scripts/getState-7.d.ts +5 -0
  21. package/dist/{esm/commands/getState-7.lua → cjs/scripts/getState-7.js} +22 -12
  22. package/dist/cjs/scripts/getState-7.js.map +1 -0
  23. package/dist/cjs/scripts/getStateV2-7.d.ts +5 -0
  24. package/dist/cjs/{commands/getStateV2-7.lua → scripts/getStateV2-7.js} +11 -10
  25. package/dist/cjs/scripts/getStateV2-7.js.map +1 -0
  26. package/dist/cjs/scripts/index.d.ts +26 -0
  27. package/dist/cjs/scripts/index.js +30 -0
  28. package/dist/cjs/scripts/index.js.map +1 -0
  29. package/dist/cjs/scripts/isFinished-3.d.ts +5 -0
  30. package/dist/cjs/{commands/isFinished-3.lua → scripts/isFinished-3.js} +11 -10
  31. package/dist/cjs/scripts/isFinished-3.js.map +1 -0
  32. package/dist/cjs/scripts/isJobInList-1.d.ts +5 -0
  33. package/dist/cjs/scripts/isJobInList-1.js +32 -0
  34. package/dist/cjs/scripts/isJobInList-1.js.map +1 -0
  35. package/dist/cjs/scripts/moveStalledJobsToWait-8.d.ts +5 -0
  36. package/dist/cjs/scripts/moveStalledJobsToWait-8.js +291 -0
  37. package/dist/cjs/scripts/moveStalledJobsToWait-8.js.map +1 -0
  38. package/dist/cjs/scripts/moveToActive-9.d.ts +5 -0
  39. package/dist/cjs/scripts/moveToActive-9.js +207 -0
  40. package/dist/cjs/scripts/moveToActive-9.js.map +1 -0
  41. package/dist/cjs/scripts/moveToDelayed-5.d.ts +5 -0
  42. package/dist/cjs/{commands/moveToDelayed-5.lua → scripts/moveToDelayed-5.js} +11 -13
  43. package/dist/cjs/scripts/moveToDelayed-5.js.map +1 -0
  44. package/dist/cjs/scripts/moveToFinished-12.d.ts +5 -0
  45. package/dist/cjs/scripts/moveToFinished-12.js +538 -0
  46. package/dist/cjs/scripts/moveToFinished-12.js.map +1 -0
  47. package/dist/cjs/scripts/moveToWaitingChildren-4.d.ts +5 -0
  48. package/dist/cjs/{commands/moveToWaitingChildren-4.lua → scripts/moveToWaitingChildren-4.js} +11 -14
  49. package/dist/cjs/scripts/moveToWaitingChildren-4.js.map +1 -0
  50. package/dist/cjs/scripts/obliterate-2.d.ts +5 -0
  51. package/dist/cjs/scripts/obliterate-2.js +241 -0
  52. package/dist/cjs/scripts/obliterate-2.js.map +1 -0
  53. package/dist/cjs/scripts/pause-4.d.ts +5 -0
  54. package/dist/{esm/commands/pause-4.lua → cjs/scripts/pause-4.js} +11 -7
  55. package/dist/cjs/scripts/pause-4.js.map +1 -0
  56. package/dist/cjs/scripts/promote-6.d.ts +5 -0
  57. package/dist/cjs/{commands/promote-6.lua → scripts/promote-6.js} +22 -14
  58. package/dist/cjs/scripts/promote-6.js.map +1 -0
  59. package/dist/cjs/scripts/releaseLock-1.d.ts +5 -0
  60. package/dist/{esm/commands/releaseLock-1.lua → cjs/scripts/releaseLock-1.js} +11 -5
  61. package/dist/cjs/scripts/releaseLock-1.js.map +1 -0
  62. package/dist/cjs/scripts/removeJob-1.d.ts +5 -0
  63. package/dist/cjs/scripts/removeJob-1.js +206 -0
  64. package/dist/cjs/scripts/removeJob-1.js.map +1 -0
  65. package/dist/cjs/scripts/removeRepeatable-2.d.ts +5 -0
  66. package/dist/cjs/{commands/removeRepeatable-2.lua → scripts/removeRepeatable-2.js} +11 -7
  67. package/dist/cjs/scripts/removeRepeatable-2.js.map +1 -0
  68. package/dist/cjs/scripts/reprocessJob-4.d.ts +5 -0
  69. package/dist/{esm/commands/reprocessJob-4.lua → cjs/scripts/reprocessJob-4.js} +11 -5
  70. package/dist/cjs/scripts/reprocessJob-4.js.map +1 -0
  71. package/dist/cjs/scripts/retryJob-6.d.ts +5 -0
  72. package/dist/{esm/commands/retryJob-6.lua → cjs/scripts/retryJob-6.js} +22 -13
  73. package/dist/cjs/scripts/retryJob-6.js.map +1 -0
  74. package/dist/cjs/scripts/retryJobs-6.d.ts +5 -0
  75. package/dist/cjs/{commands/retryJobs-6.lua → scripts/retryJobs-6.js} +38 -15
  76. package/dist/cjs/scripts/retryJobs-6.js.map +1 -0
  77. package/dist/cjs/scripts/takeLock-1.d.ts +5 -0
  78. package/dist/cjs/{commands/takeLock-1.lua → scripts/takeLock-1.js} +11 -4
  79. package/dist/cjs/scripts/takeLock-1.js.map +1 -0
  80. package/dist/cjs/scripts/updateData-1.d.ts +5 -0
  81. package/dist/cjs/scripts/updateData-1.js +23 -0
  82. package/dist/cjs/scripts/updateData-1.js.map +1 -0
  83. package/dist/cjs/scripts/updateProgress-2.d.ts +5 -0
  84. package/dist/{esm/commands/updateProgress-2.lua → cjs/scripts/updateProgress-2.js} +11 -5
  85. package/dist/cjs/scripts/updateProgress-2.js.map +1 -0
  86. package/dist/esm/classes/job.d.ts +1 -1
  87. package/dist/esm/classes/redis-connection.d.ts +6 -2
  88. package/dist/esm/classes/redis-connection.js +11 -5
  89. package/dist/esm/classes/redis-connection.js.map +1 -1
  90. package/dist/esm/scripts/addJob-8.d.ts +5 -0
  91. package/dist/{cjs/commands/addJob-8.lua → esm/scripts/addJob-8.js} +80 -31
  92. package/dist/esm/scripts/addJob-8.js.map +1 -0
  93. package/dist/esm/scripts/changeDelay-4.d.ts +5 -0
  94. package/dist/esm/{commands/changeDelay-4.lua → scripts/changeDelay-4.js} +8 -11
  95. package/dist/esm/scripts/changeDelay-4.js.map +1 -0
  96. package/dist/esm/scripts/cleanJobsInSet-2.d.ts +5 -0
  97. package/dist/esm/scripts/cleanJobsInSet-2.js +261 -0
  98. package/dist/esm/scripts/cleanJobsInSet-2.js.map +1 -0
  99. package/dist/esm/scripts/drain-4.d.ts +5 -0
  100. package/dist/esm/{commands/includes/removeParentDependencyKey.lua → scripts/drain-4.js} +107 -10
  101. package/dist/esm/scripts/drain-4.js.map +1 -0
  102. package/dist/esm/scripts/extendLock-2.d.ts +5 -0
  103. package/dist/{cjs/commands/extendLock-2.lua → esm/scripts/extendLock-2.js} +8 -4
  104. package/dist/esm/scripts/extendLock-2.js.map +1 -0
  105. package/dist/esm/scripts/getState-7.d.ts +5 -0
  106. package/dist/{cjs/commands/getState-7.lua → esm/scripts/getState-7.js} +19 -12
  107. package/dist/esm/scripts/getState-7.js.map +1 -0
  108. package/dist/esm/scripts/getStateV2-7.d.ts +5 -0
  109. package/dist/esm/{commands/getStateV2-7.lua → scripts/getStateV2-7.js} +8 -10
  110. package/dist/esm/scripts/getStateV2-7.js.map +1 -0
  111. package/dist/esm/scripts/index.d.ts +26 -0
  112. package/dist/esm/scripts/index.js +27 -0
  113. package/dist/esm/scripts/index.js.map +1 -0
  114. package/dist/esm/scripts/isFinished-3.d.ts +5 -0
  115. package/dist/esm/{commands/isFinished-3.lua → scripts/isFinished-3.js} +8 -10
  116. package/dist/esm/scripts/isFinished-3.js.map +1 -0
  117. package/dist/esm/scripts/isJobInList-1.d.ts +5 -0
  118. package/dist/esm/scripts/isJobInList-1.js +29 -0
  119. package/dist/esm/scripts/isJobInList-1.js.map +1 -0
  120. package/dist/esm/scripts/moveStalledJobsToWait-8.d.ts +5 -0
  121. package/dist/esm/scripts/moveStalledJobsToWait-8.js +288 -0
  122. package/dist/esm/scripts/moveStalledJobsToWait-8.js.map +1 -0
  123. package/dist/esm/scripts/moveToActive-9.d.ts +5 -0
  124. package/dist/esm/scripts/moveToActive-9.js +204 -0
  125. package/dist/esm/scripts/moveToActive-9.js.map +1 -0
  126. package/dist/esm/scripts/moveToDelayed-5.d.ts +5 -0
  127. package/dist/esm/{commands/moveToDelayed-5.lua → scripts/moveToDelayed-5.js} +8 -13
  128. package/dist/esm/scripts/moveToDelayed-5.js.map +1 -0
  129. package/dist/esm/scripts/moveToFinished-12.d.ts +5 -0
  130. package/dist/esm/scripts/moveToFinished-12.js +535 -0
  131. package/dist/esm/scripts/moveToFinished-12.js.map +1 -0
  132. package/dist/esm/scripts/moveToWaitingChildren-4.d.ts +5 -0
  133. package/dist/esm/{commands/moveToWaitingChildren-4.lua → scripts/moveToWaitingChildren-4.js} +8 -14
  134. package/dist/esm/scripts/moveToWaitingChildren-4.js.map +1 -0
  135. package/dist/esm/scripts/obliterate-2.d.ts +5 -0
  136. package/dist/esm/scripts/obliterate-2.js +238 -0
  137. package/dist/esm/scripts/obliterate-2.js.map +1 -0
  138. package/dist/esm/scripts/pause-4.d.ts +5 -0
  139. package/dist/{cjs/commands/pause-4.lua → esm/scripts/pause-4.js} +8 -7
  140. package/dist/esm/scripts/pause-4.js.map +1 -0
  141. package/dist/esm/scripts/promote-6.d.ts +5 -0
  142. package/dist/esm/{commands/promote-6.lua → scripts/promote-6.js} +19 -14
  143. package/dist/esm/scripts/promote-6.js.map +1 -0
  144. package/dist/esm/scripts/releaseLock-1.d.ts +5 -0
  145. package/dist/{cjs/commands/releaseLock-1.lua → esm/scripts/releaseLock-1.js} +8 -5
  146. package/dist/esm/scripts/releaseLock-1.js.map +1 -0
  147. package/dist/esm/scripts/removeJob-1.d.ts +5 -0
  148. package/dist/esm/scripts/removeJob-1.js +203 -0
  149. package/dist/esm/scripts/removeJob-1.js.map +1 -0
  150. package/dist/esm/scripts/removeRepeatable-2.d.ts +5 -0
  151. package/dist/esm/{commands/removeRepeatable-2.lua → scripts/removeRepeatable-2.js} +8 -7
  152. package/dist/esm/scripts/removeRepeatable-2.js.map +1 -0
  153. package/dist/esm/scripts/reprocessJob-4.d.ts +5 -0
  154. package/dist/{cjs/commands/reprocessJob-4.lua → esm/scripts/reprocessJob-4.js} +8 -5
  155. package/dist/esm/scripts/reprocessJob-4.js.map +1 -0
  156. package/dist/esm/scripts/retryJob-6.d.ts +5 -0
  157. package/dist/{cjs/commands/retryJob-6.lua → esm/scripts/retryJob-6.js} +19 -13
  158. package/dist/esm/scripts/retryJob-6.js.map +1 -0
  159. package/dist/esm/scripts/retryJobs-6.d.ts +5 -0
  160. package/dist/esm/{commands/retryJobs-6.lua → scripts/retryJobs-6.js} +35 -15
  161. package/dist/esm/scripts/retryJobs-6.js.map +1 -0
  162. package/dist/esm/scripts/takeLock-1.d.ts +5 -0
  163. package/dist/esm/{commands/takeLock-1.lua → scripts/takeLock-1.js} +8 -4
  164. package/dist/esm/scripts/takeLock-1.js.map +1 -0
  165. package/dist/esm/scripts/updateData-1.d.ts +5 -0
  166. package/dist/esm/{commands/updateData-1.lua → scripts/updateData-1.js} +8 -4
  167. package/dist/esm/scripts/updateData-1.js.map +1 -0
  168. package/dist/esm/scripts/updateProgress-2.d.ts +5 -0
  169. package/dist/{cjs/commands/updateProgress-2.lua → esm/scripts/updateProgress-2.js} +8 -5
  170. package/dist/esm/scripts/updateProgress-2.js.map +1 -0
  171. package/package.json +4 -2
  172. package/dist/cjs/commands/cleanJobsInSet-2.lua +0 -46
  173. package/dist/cjs/commands/drain-4.lua +0 -25
  174. package/dist/cjs/commands/includes/addJobWithPriority.lua +0 -16
  175. package/dist/cjs/commands/includes/batches.lua +0 -18
  176. package/dist/cjs/commands/includes/checkItemInList.lua +0 -12
  177. package/dist/cjs/commands/includes/checkStalledJobs.lua +0 -137
  178. package/dist/cjs/commands/includes/cleanList.lua +0 -50
  179. package/dist/cjs/commands/includes/cleanSet.lua +0 -50
  180. package/dist/cjs/commands/includes/collectMetrics.lua +0 -46
  181. package/dist/cjs/commands/includes/destructureJobKey.lua +0 -12
  182. package/dist/cjs/commands/includes/getNextDelayedTimestamp.lua +0 -13
  183. package/dist/cjs/commands/includes/getTargetQueueList.lua +0 -12
  184. package/dist/cjs/commands/includes/getTimestamp.lua +0 -19
  185. package/dist/cjs/commands/includes/getZSetItems.lua +0 -7
  186. package/dist/cjs/commands/includes/isLocked.lua +0 -31
  187. package/dist/cjs/commands/includes/moveJobFromWaitToActive.lua +0 -84
  188. package/dist/cjs/commands/includes/moveParentFromWaitingChildrenToFailed.lua +0 -25
  189. package/dist/cjs/commands/includes/promoteDelayedJobs.lua +0 -49
  190. package/dist/cjs/commands/includes/removeJob.lua +0 -13
  191. package/dist/cjs/commands/includes/removeJobFromAnyState.lua +0 -26
  192. package/dist/cjs/commands/includes/removeJobs.lua +0 -38
  193. package/dist/cjs/commands/includes/removeJobsByMaxAge.lua +0 -15
  194. package/dist/cjs/commands/includes/removeJobsByMaxCount.lua +0 -15
  195. package/dist/cjs/commands/includes/trimEvents.lua +0 -12
  196. package/dist/cjs/commands/includes/updateParentDepsIfNeeded.lua +0 -28
  197. package/dist/cjs/commands/isJobInList-1.lua +0 -16
  198. package/dist/cjs/commands/moveStalledJobsToWait-8.lua +0 -24
  199. package/dist/cjs/commands/moveToActive-9.lua +0 -67
  200. package/dist/cjs/commands/moveToFinished-12.lua +0 -201
  201. package/dist/cjs/commands/obliterate-2.lua +0 -94
  202. package/dist/cjs/commands/removeJob-1.lua +0 -72
  203. package/dist/cjs/commands/updateData-1.lua +0 -16
  204. package/dist/esm/commands/cleanJobsInSet-2.lua +0 -46
  205. package/dist/esm/commands/drain-4.lua +0 -25
  206. package/dist/esm/commands/includes/addJobWithPriority.lua +0 -16
  207. package/dist/esm/commands/includes/batches.lua +0 -18
  208. package/dist/esm/commands/includes/checkItemInList.lua +0 -12
  209. package/dist/esm/commands/includes/checkStalledJobs.lua +0 -137
  210. package/dist/esm/commands/includes/cleanList.lua +0 -50
  211. package/dist/esm/commands/includes/cleanSet.lua +0 -50
  212. package/dist/esm/commands/includes/collectMetrics.lua +0 -46
  213. package/dist/esm/commands/includes/destructureJobKey.lua +0 -12
  214. package/dist/esm/commands/includes/getNextDelayedTimestamp.lua +0 -13
  215. package/dist/esm/commands/includes/getTargetQueueList.lua +0 -12
  216. package/dist/esm/commands/includes/getTimestamp.lua +0 -19
  217. package/dist/esm/commands/includes/getZSetItems.lua +0 -7
  218. package/dist/esm/commands/includes/isLocked.lua +0 -31
  219. package/dist/esm/commands/includes/moveJobFromWaitToActive.lua +0 -84
  220. package/dist/esm/commands/includes/moveParentFromWaitingChildrenToFailed.lua +0 -25
  221. package/dist/esm/commands/includes/promoteDelayedJobs.lua +0 -49
  222. package/dist/esm/commands/includes/removeJob.lua +0 -13
  223. package/dist/esm/commands/includes/removeJobFromAnyState.lua +0 -26
  224. package/dist/esm/commands/includes/removeJobs.lua +0 -38
  225. package/dist/esm/commands/includes/removeJobsByMaxAge.lua +0 -15
  226. package/dist/esm/commands/includes/removeJobsByMaxCount.lua +0 -15
  227. package/dist/esm/commands/includes/trimEvents.lua +0 -12
  228. package/dist/esm/commands/includes/updateParentDepsIfNeeded.lua +0 -28
  229. package/dist/esm/commands/isJobInList-1.lua +0 -16
  230. package/dist/esm/commands/moveStalledJobsToWait-8.lua +0 -24
  231. package/dist/esm/commands/moveToActive-9.lua +0 -67
  232. package/dist/esm/commands/moveToFinished-12.lua +0 -201
  233. package/dist/esm/commands/obliterate-2.lua +0 -94
  234. package/dist/esm/commands/removeJob-1.lua +0 -72
@@ -1,17 +1,14 @@
1
- --[[
1
+ const content = `--[[
2
2
  Attempts to reprocess a job
3
-
4
3
  Input:
5
4
  KEYS[1] job key
6
5
  KEYS[2] events stream
7
6
  KEYS[3] job state
8
7
  KEYS[4] wait key
9
-
10
8
  ARGV[1] job.id
11
9
  ARGV[2] (job.opts.lifo ? 'R' : 'L') + 'PUSH'
12
10
  ARGV[3] propVal - failedReason/returnvalue
13
11
  ARGV[4] prev state - failed/completed
14
-
15
12
  Output:
16
13
  1 means the operation was a success
17
14
  -1 means the job does not exist
@@ -23,7 +20,6 @@ if (rcall("EXISTS", KEYS[1]) == 1) then
23
20
  if (rcall("ZREM", KEYS[3], jobId) == 1) then
24
21
  rcall(ARGV[2], KEYS[4], jobId)
25
22
  rcall("HDEL", KEYS[1], "finishedOn", "processedOn", ARGV[3])
26
-
27
23
  -- Emit waiting event
28
24
  rcall("XADD", KEYS[2], "*", "event", "waiting", "jobId", jobId, "prev", ARGV[4]);
29
25
  return 1
@@ -33,3 +29,10 @@ if (rcall("EXISTS", KEYS[1]) == 1) then
33
29
  else
34
30
  return -1
35
31
  end
32
+ `;
33
+ export const reprocessJob = {
34
+ name: 'reprocessJob',
35
+ content,
36
+ keys: 4,
37
+ };
38
+ //# sourceMappingURL=reprocessJob-4.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reprocessJob-4.js","sourceRoot":"","sources":["../../../src/scripts/reprocessJob-4.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+Bf,CAAC;AACF,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,IAAI,EAAE,cAAc;IACpB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
@@ -0,0 +1,5 @@
1
+ export declare const retryJob: {
2
+ name: string;
3
+ content: string;
4
+ keys: number;
5
+ };
@@ -1,6 +1,5 @@
1
- --[[
1
+ const content = `--[[
2
2
  Retries a failed job by moving it back to the wait queue.
3
-
4
3
  Input:
5
4
  KEYS[1] 'active',
6
5
  KEYS[2] 'wait'
@@ -8,26 +7,30 @@
8
7
  KEYS[4] job key
9
8
  KEYS[5] 'meta'
10
9
  KEYS[6] events stream
11
-
12
10
  ARGV[1] pushCmd
13
11
  ARGV[2] jobId
14
12
  ARGV[3] token
15
-
16
13
  Events:
17
14
  'waiting'
18
-
19
15
  Output:
20
16
  0 - OK
21
17
  -1 - Missing key
22
18
  -2 - Missing lock
23
19
  ]]
24
20
  local rcall = redis.call
25
-
26
21
  -- Includes
27
- --- @include "includes/getTargetQueueList"
28
-
22
+ --[[
23
+ Function to check for the meta.paused key to decide if we are paused or not
24
+ (since an empty list and !EXISTS are not really the same).
25
+ ]]
26
+ local function getTargetQueueList(queueMetaKey, waitKey, pausedKey)
27
+ if rcall("HEXISTS", queueMetaKey, "paused") ~= 1 then
28
+ return waitKey
29
+ else
30
+ return pausedKey
31
+ end
32
+ end
29
33
  if rcall("EXISTS", KEYS[4]) == 1 then
30
-
31
34
  if ARGV[3] ~= "0" then
32
35
  local lockKey = KEYS[4] .. ':lock'
33
36
  if rcall("GET", lockKey) == ARGV[3] then
@@ -36,16 +39,19 @@ if rcall("EXISTS", KEYS[4]) == 1 then
36
39
  return -2
37
40
  end
38
41
  end
39
-
40
42
  local target = getTargetQueueList(KEYS[5], KEYS[2], KEYS[3])
41
-
42
43
  rcall("LREM", KEYS[1], 0, ARGV[2])
43
44
  rcall(ARGV[1], target, ARGV[2])
44
-
45
45
  -- Emit waiting event
46
46
  rcall("XADD", KEYS[6], "*", "event", "waiting", "jobId", ARGV[2], "prev", "failed");
47
-
48
47
  return 0
49
48
  else
50
49
  return -1
51
50
  end
51
+ `;
52
+ export const retryJob = {
53
+ name: 'retryJob',
54
+ content,
55
+ keys: 6,
56
+ };
57
+ //# sourceMappingURL=retryJob-6.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"retryJob-6.js","sourceRoot":"","sources":["../../../src/scripts/retryJob-6.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkDf,CAAC;AACF,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,IAAI,EAAE,UAAU;IAChB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
@@ -0,0 +1,5 @@
1
+ export declare const retryJobs: {
2
+ name: string;
3
+ content: string;
4
+ keys: number;
5
+ };
@@ -1,6 +1,5 @@
1
- --[[
1
+ const content = `--[[
2
2
  Attempts to retry all failed jobs
3
-
4
3
  Input:
5
4
  KEYS[1] base key
6
5
  KEYS[2] events stream
@@ -8,46 +7,67 @@
8
7
  KEYS[4] 'wait'
9
8
  KEYS[5] 'paused'
10
9
  KEYS[6] 'meta'
11
-
12
10
  ARGV[1] count
13
11
  ARGV[2] timestamp
14
12
  ARGV[3] prev state
15
-
16
13
  Output:
17
14
  1 means the operation is not completed
18
15
  0 means the operation is completed
19
16
  ]]
20
17
  local maxCount = tonumber(ARGV[1])
21
18
  local timestamp = tonumber(ARGV[2])
22
-
23
19
  local rcall = redis.call;
24
-
25
20
  -- Includes
26
- --- @include "includes/batches"
27
- --- @include "includes/getTargetQueueList"
28
-
21
+ --[[
22
+ Function to loop in batches.
23
+ Just a bit of warning, some commands as ZREM
24
+ could receive a maximum of 7000 parameters per call.
25
+ ]]
26
+ local function batches(n, batchSize)
27
+ local i = 0
28
+ return function()
29
+ local from = i * batchSize + 1
30
+ i = i + 1
31
+ if (from <= n) then
32
+ local to = math.min(from + batchSize - 1, n)
33
+ return from, to
34
+ end
35
+ end
36
+ end
37
+ --[[
38
+ Function to check for the meta.paused key to decide if we are paused or not
39
+ (since an empty list and !EXISTS are not really the same).
40
+ ]]
41
+ local function getTargetQueueList(queueMetaKey, waitKey, pausedKey)
42
+ if rcall("HEXISTS", queueMetaKey, "paused") ~= 1 then
43
+ return waitKey
44
+ else
45
+ return pausedKey
46
+ end
47
+ end
29
48
  local target = getTargetQueueList(KEYS[6], KEYS[4], KEYS[5])
30
-
31
49
  local jobs = rcall('ZRANGEBYSCORE', KEYS[3], 0, timestamp, 'LIMIT', 0, maxCount)
32
50
  if (#jobs > 0) then
33
51
  for i, key in ipairs(jobs) do
34
52
  local jobKey = KEYS[1] .. key
35
53
  rcall("HDEL", jobKey, "finishedOn", "processedOn", "failedReason", "returnvalue")
36
-
37
54
  -- Emit waiting event
38
55
  rcall("XADD", KEYS[2], "*", "event", "waiting", "jobId", key, "prev", ARGV[3]);
39
56
  end
40
-
41
57
  for from, to in batches(#jobs, 7000) do
42
58
  rcall("ZREM", KEYS[3], unpack(jobs, from, to))
43
59
  rcall("LPUSH", target, unpack(jobs, from, to))
44
60
  end
45
61
  end
46
-
47
62
  maxCount = maxCount - #jobs
48
-
49
63
  if(maxCount <= 0) then
50
64
  return 1
51
65
  end
52
-
53
66
  return 0
67
+ `;
68
+ export const retryJobs = {
69
+ name: 'retryJobs',
70
+ content,
71
+ keys: 6,
72
+ };
73
+ //# sourceMappingURL=retryJobs-6.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"retryJobs-6.js","sourceRoot":"","sources":["../../../src/scripts/retryJobs-6.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkEf,CAAC;AACF,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,IAAI,EAAE,WAAW;IACjB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
@@ -0,0 +1,5 @@
1
+ export declare const takeLock: {
2
+ name: string;
3
+ content: string;
4
+ keys: number;
5
+ };
@@ -1,12 +1,9 @@
1
- --[[
1
+ const content = `--[[
2
2
  Takes a lock
3
-
4
3
  Input:
5
4
  KEYS[1] 'lock',
6
-
7
5
  ARGV[1] token
8
6
  ARGV[2] lock duration in milliseconds
9
-
10
7
  Output:
11
8
  "OK" if lock extented succesfully.
12
9
  ]]
@@ -15,3 +12,10 @@ if redis.call("SET", KEYS[1], ARGV[1], "NX", "PX", ARGV[2]) then
15
12
  else
16
13
  return 0
17
14
  end
15
+ `;
16
+ export const takeLock = {
17
+ name: 'takeLock',
18
+ content,
19
+ keys: 1,
20
+ };
21
+ //# sourceMappingURL=takeLock-1.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"takeLock-1.js","sourceRoot":"","sources":["../../../src/scripts/takeLock-1.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;CAcf,CAAC;AACF,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,IAAI,EAAE,UAAU;IAChB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
@@ -0,0 +1,5 @@
1
+ export declare const updateData: {
2
+ name: string;
3
+ content: string;
4
+ keys: number;
5
+ };
@@ -1,16 +1,20 @@
1
- --[[
1
+ const content = `--[[
2
2
  Update job data
3
-
4
3
  Input:
5
4
  KEYS[1] Job id key
6
-
7
5
  ARGV[1] data
8
6
  ]]
9
7
  local rcall = redis.call
10
-
11
8
  if rcall("EXISTS",KEYS[1]) == 1 then -- // Make sure job exists
12
9
  rcall("HSET", KEYS[1], "data", ARGV[1])
13
10
  return 0
14
11
  else
15
12
  return -1
16
13
  end
14
+ `;
15
+ export const updateData = {
16
+ name: 'updateData',
17
+ content,
18
+ keys: 1,
19
+ };
20
+ //# sourceMappingURL=updateData-1.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"updateData-1.js","sourceRoot":"","sources":["../../../src/scripts/updateData-1.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;CAaf,CAAC;AACF,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,IAAI,EAAE,YAAY;IAClB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
@@ -0,0 +1,5 @@
1
+ export declare const updateProgress: {
2
+ name: string;
3
+ content: string;
4
+ keys: number;
5
+ };
@@ -1,18 +1,14 @@
1
- --[[
1
+ const content = `--[[
2
2
  Update job progress
3
-
4
3
  Input:
5
4
  KEYS[1] Job id key
6
5
  KEYS[2] event stream key
7
-
8
6
  ARGV[1] id
9
7
  ARGV[2] progress
10
-
11
8
  Event:
12
9
  progress(jobId, progress)
13
10
  ]]
14
11
  local rcall = redis.call
15
-
16
12
  if rcall("EXISTS",KEYS[1]) == 1 then -- // Make sure job exists
17
13
  rcall("HSET", KEYS[1], "progress", ARGV[2])
18
14
  rcall("XADD", KEYS[2], "*", "event", "progress", "jobId", ARGV[1], "data", ARGV[2]);
@@ -20,3 +16,10 @@ if rcall("EXISTS",KEYS[1]) == 1 then -- // Make sure job exists
20
16
  else
21
17
  return -1
22
18
  end
19
+ `;
20
+ export const updateProgress = {
21
+ name: 'updateProgress',
22
+ content,
23
+ keys: 2,
24
+ };
25
+ //# sourceMappingURL=updateProgress-2.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"updateProgress-2.js","sourceRoot":"","sources":["../../../src/scripts/updateProgress-2.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;CAkBf,CAAC;AACF,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,IAAI,EAAE,gBAAgB;IACtB,OAAO;IACP,IAAI,EAAE,CAAC;CACR,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bullmq",
3
- "version": "2.2.0",
3
+ "version": "2.2.1",
4
4
  "description": "Queue for messages and jobs based on Redis",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "module": "./dist/esm/index.js",
@@ -19,7 +19,7 @@
19
19
  "dist"
20
20
  ],
21
21
  "scripts": {
22
- "build": "npm-run-all tsc:all copy:lua copy:includes:lua clean:temp:files",
22
+ "build": "npm-run-all pretest tsc:all clean:temp:files",
23
23
  "clean:temp:files": "rimraf dist/cjs/bullmq.d.ts dist/esm/bullmq.d.ts dist/tsdoc-metadata.json",
24
24
  "copy:lua": "copyfiles -f ./src/commands/*.lua ./dist/cjs/commands && copyfiles -f ./src/commands/*.lua ./dist/esm/commands",
25
25
  "copy:includes:lua": "copyfiles -f ./src/commands/includes/*.lua ./dist/cjs/commands/includes && copyfiles -f ./src/commands/includes/*.lua ./dist/esm/commands/includes",
@@ -39,6 +39,8 @@
39
39
  "pretty:quick": "pretty-quick --ignore-path ./.eslintignore --staged",
40
40
  "semantic-release": "semantic-release",
41
41
  "semantic-release-prepare": "ts-node tools/semantic-release-prepare",
42
+ "transform:commands": "node ./commandTransform.js ./rawScripts ./src/scripts",
43
+ "pretest": "npm-run-all generate:raw:scripts transform:commands",
42
44
  "test": "ts-mocha -p tsconfig-cjs.json --config ./.mocharc.js",
43
45
  "test:watch": "ts-mocha -p tsconfig-cjs.json --paths 'tests/test_*.ts' -w --watch-extensions ts",
44
46
  "tsc": "tsc",
@@ -1,46 +0,0 @@
1
- --[[
2
- Remove jobs from the specific set.
3
-
4
- Input:
5
- KEYS[1] set key,
6
- KEYS[2] events stream key
7
-
8
- ARGV[1] jobKey prefix
9
- ARGV[2] timestamp
10
- ARGV[3] limit the number of jobs to be removed. 0 is unlimited
11
- ARGV[4] set name, can be any of 'wait', 'active', 'paused', 'delayed', 'completed', or 'failed'
12
- ]]
13
- local rcall = redis.call
14
- local rangeStart = 0
15
- local rangeEnd = -1
16
-
17
- local limit = tonumber(ARGV[3])
18
-
19
- -- If we're only deleting _n_ items, avoid retrieving all items
20
- -- for faster performance
21
- --
22
- -- Start from the tail of the list, since that's where oldest elements
23
- -- are generally added for FIFO lists
24
- if limit > 0 then
25
- rangeStart = -1 - limit + 1
26
- rangeEnd = -1
27
- end
28
-
29
- -- Includes
30
- --- @include "includes/cleanList"
31
- --- @include "includes/cleanSet"
32
-
33
- local result
34
- if ARGV[4] == "active" then
35
- result = cleanList(KEYS[1], ARGV[1], rangeStart, rangeEnd, ARGV[2], false)
36
- elseif ARGV[4] == "delayed" then
37
- result = cleanSet(KEYS[1], ARGV[1], rangeStart, rangeEnd, ARGV[2], limit, {"processedOn", "timestamp"})
38
- elseif ARGV[4] == "wait" or ARGV[4] == "paused" then
39
- result = cleanList(KEYS[1], ARGV[1], rangeStart, rangeEnd, ARGV[2], true)
40
- else
41
- result = cleanSet(KEYS[1], ARGV[1], rangeStart, rangeEnd, ARGV[2], limit, {"finishedOn"} )
42
- end
43
-
44
- rcall("XADD", KEYS[2], "*", "event", "cleaned", "count", result[2])
45
-
46
- return result[1]
@@ -1,25 +0,0 @@
1
- --[[
2
- Drains the queue, removes all jobs that are waiting
3
- or delayed, but not active, completed or failed
4
-
5
- Input:
6
- KEYS[1] 'wait',
7
- KEYS[2] 'paused'
8
- KEYS[3] 'delayed'
9
- KEYS[4] 'priority'
10
-
11
- ARGV[1] queue key prefix
12
- ]]
13
- local rcall = redis.call
14
- local queueBaseKey = ARGV[1]
15
-
16
- --- @include "includes/removeJobs"
17
-
18
- removeListJobs(KEYS[1], true, queueBaseKey, 0) --wait
19
- removeListJobs(KEYS[2], true, queueBaseKey, 0) --paused
20
-
21
- if KEYS[3] ~= "" then
22
- removeZSetJobs(KEYS[3], true, queueBaseKey, 0) --delayed
23
- end
24
-
25
- rcall("DEL", KEYS[4])
@@ -1,16 +0,0 @@
1
- --[[
2
- Function to add job considering priority.
3
- ]]
4
-
5
- local function addJobWithPriority(priorityKey, priority, targetKey, jobId)
6
- rcall("ZADD", priorityKey, priority, jobId)
7
- local count = rcall("ZCOUNT", priorityKey, 0, priority)
8
-
9
- local len = rcall("LLEN", targetKey)
10
- local id = rcall("LINDEX", targetKey, len - (count - 1))
11
- if id then
12
- rcall("LINSERT", targetKey, "BEFORE", id, jobId)
13
- else
14
- rcall("RPUSH", targetKey, jobId)
15
- end
16
- end
@@ -1,18 +0,0 @@
1
- --[[
2
- Function to loop in batches.
3
- Just a bit of warning, some commands as ZREM
4
- could receive a maximum of 7000 parameters per call.
5
- ]]
6
-
7
- local function batches(n, batchSize)
8
- local i = 0
9
-
10
- return function()
11
- local from = i * batchSize + 1
12
- i = i + 1
13
- if (from <= n) then
14
- local to = math.min(from + batchSize - 1, n)
15
- return from, to
16
- end
17
- end
18
- end
@@ -1,12 +0,0 @@
1
- --[[
2
- Functions to check if a item belongs to a list.
3
- ]]
4
-
5
- local function checkItemInList(list, item)
6
- for _, v in pairs(list) do
7
- if v == item then
8
- return 1
9
- end
10
- end
11
- return nil
12
- end
@@ -1,137 +0,0 @@
1
- --[[
2
- Move stalled jobs to wait.
3
-
4
- Input:
5
- stalledKey 'stalled' (SET)
6
- waitKey 'wait', (LIST)
7
- activeKey 'active', (LIST)
8
- failedKey 'failed', (ZSET)
9
- stalledCheckKey 'stalled-check', (KEY)
10
- metaKey 'meta', (KEY)
11
- pausedKey 'paused', (LIST)
12
- eventStreamKey 'event stream' (STREAM)
13
-
14
- maxStalledJobCount Max stalled job count
15
- queueKeyPrefix queue.toKey('')
16
- timestamp timestamp
17
- maxCheckTime max check time
18
-
19
- Events:
20
- 'stalled' with stalled job id.
21
- ]] local rcall = redis.call
22
-
23
- -- Includes
24
- --- @include "batches"
25
- --- @include "getTargetQueueList"
26
- --- @include "removeJob"
27
- --- @include "removeJobsByMaxAge"
28
- --- @include "removeJobsByMaxCount"
29
- --- @include "trimEvents"
30
-
31
- -- Check if we need to check for stalled jobs now.
32
-
33
- local function checkStalledJobs(stalledKey, waitKey, activeKey, failedKey, stalledCheckKey,
34
- metaKey, pausedKey, eventStreamKey, maxStalledJobCount, queueKeyPrefix, timestamp, maxCheckTime)
35
- if rcall("EXISTS", stalledCheckKey) == 1 then
36
- return {{}, {}}
37
- end
38
-
39
- rcall("SET", stalledCheckKey, timestamp, "PX", maxCheckTime)
40
-
41
- -- Trim events before emiting them to avoid trimming events emitted in this script
42
- trimEvents(metaKey, eventStreamKey)
43
-
44
- -- Move all stalled jobs to wait
45
- local stalling = rcall('SMEMBERS', stalledKey)
46
- local stalled = {}
47
- local failed = {}
48
- if (#stalling > 0) then
49
- rcall('DEL', stalledKey)
50
-
51
- local MAX_STALLED_JOB_COUNT = tonumber(maxStalledJobCount)
52
-
53
- -- Remove from active list
54
- for i, jobId in ipairs(stalling) do
55
-
56
- if jobId == '0' then
57
- -- If the jobId is a delay marker ID we just remove it.
58
- local removed = rcall("LREM", activeKey, 1, jobId)
59
- else
60
- local jobKey = queueKeyPrefix .. jobId
61
-
62
- -- Check that the lock is also missing, then we can handle this job as really stalled.
63
- if (rcall("EXISTS", jobKey .. ":lock") == 0) then
64
- -- Remove from the active queue.
65
- local removed = rcall("LREM", activeKey, 1, jobId)
66
-
67
- if (removed > 0) then
68
- -- If this job has been stalled too many times, such as if it crashes the worker, then fail it.
69
- local stalledCount =
70
- rcall("HINCRBY", jobKey, "stalledCounter", 1)
71
- if (stalledCount > MAX_STALLED_JOB_COUNT) then
72
- local rawOpts = rcall("HGET", jobKey, "opts")
73
- local opts = cjson.decode(rawOpts)
74
- local removeOnFailType = type(opts["removeOnFail"])
75
- rcall("ZADD", failedKey, timestamp, jobId)
76
- local failedReason =
77
- "job stalled more than allowable limit"
78
- rcall("HMSET", jobKey, "failedReason", failedReason,
79
- "finishedOn", timestamp)
80
- rcall("XADD", eventStreamKey, "*", "event", "failed", "jobId",
81
- jobId, 'prev', 'active', 'failedReason',
82
- failedReason)
83
-
84
- if removeOnFailType == "number" then
85
- removeJobsByMaxCount(opts["removeOnFail"], failedKey,
86
- queueKeyPrefix)
87
- elseif removeOnFailType == "boolean" then
88
- if opts["removeOnFail"] then
89
- removeJob(jobId, false, queueKeyPrefix)
90
- rcall("ZREM", failedKey, jobId)
91
- end
92
- elseif removeOnFailType ~= "nil" then
93
- local maxAge = opts["removeOnFail"]["age"]
94
- local maxCount = opts["removeOnFail"]["count"]
95
-
96
- if maxAge ~= nil then
97
- removeJobsByMaxAge(timestamp, maxAge, failedKey,
98
- queueKeyPrefix)
99
- end
100
-
101
- if maxCount ~= nil and maxCount > 0 then
102
- removeJobsByMaxCount(maxCount, failedKey, queueKeyPrefix)
103
- end
104
- end
105
-
106
- table.insert(failed, jobId)
107
- else
108
- local target = getTargetQueueList(metaKey, waitKey,
109
- pausedKey)
110
-
111
- -- Move the job back to the wait queue, to immediately be picked up by a waiting worker.
112
- rcall("RPUSH", target, jobId)
113
- rcall("XADD", eventStreamKey, "*", "event", "waiting", "jobId",
114
- jobId, 'prev', 'active')
115
-
116
- -- Emit the stalled event
117
- rcall("XADD", eventStreamKey, "*", "event", "stalled", "jobId",
118
- jobId)
119
- table.insert(stalled, jobId)
120
- end
121
- end
122
- end
123
- end
124
- end
125
- end
126
-
127
- -- Mark potentially stalled jobs
128
- local active = rcall('LRANGE', activeKey, 0, -1)
129
-
130
- if (#active > 0) then
131
- for from, to in batches(#active, 7000) do
132
- rcall('SADD', stalledKey, unpack(active, from, to))
133
- end
134
- end
135
-
136
- return {failed, stalled}
137
- end
@@ -1,50 +0,0 @@
1
- --[[
2
- Function to clean job list.
3
- Returns jobIds and deleted count number.
4
- ]]
5
-
6
- -- Includes
7
- --- @include "getTimestamp"
8
- --- @include "removeJob"
9
-
10
- local function cleanList(listKey, jobKeyPrefix, rangeStart, rangeEnd,
11
- timestamp, isWaiting)
12
- local jobs = rcall("LRANGE", listKey, rangeStart, rangeEnd)
13
- local deleted = {}
14
- local deletedCount = 0
15
- local jobTS
16
- local deletionMarker = ''
17
- local jobIdsLen = #jobs
18
- for i, job in ipairs(jobs) do
19
- if limit > 0 and deletedCount >= limit then
20
- break
21
- end
22
-
23
- local jobKey = jobKeyPrefix .. job
24
- if (isWaiting or rcall("EXISTS", jobKey .. ":lock") == 0) then
25
- -- Find the right timestamp of the job to compare to maxTimestamp:
26
- -- * finishedOn says when the job was completed, but it isn't set unless the job has actually completed
27
- -- * processedOn represents when the job was last attempted, but it doesn't get populated until
28
- -- the job is first tried
29
- -- * timestamp is the original job submission time
30
- -- Fetch all three of these (in that order) and use the first one that is set so that we'll leave jobs
31
- -- that have been active within the grace period:
32
- jobTS = getTimestamp(jobKey, {"finishedOn", "processedOn", "timestamp"})
33
- if (not jobTS or jobTS < timestamp) then
34
- -- replace the entry with a deletion marker; the actual deletion will
35
- -- occur at the end of the script
36
- rcall("LSET", listKey, rangeEnd - jobIdsLen + i, deletionMarker)
37
- removeJob(job, true, jobKeyPrefix)
38
- if isWaiting then
39
- rcall("ZREM", jobKeyPrefix .. "priority", job)
40
- end
41
- deletedCount = deletedCount + 1
42
- table.insert(deleted, job)
43
- end
44
- end
45
- end
46
-
47
- rcall("LREM", listKey, 0, deletionMarker)
48
-
49
- return {deleted, deletedCount}
50
- end