@tachybase/plugin-adapter-bullmq 1.3.16 → 1.3.18

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 (348) hide show
  1. package/dist/externalVersion.js +2 -2
  2. package/dist/index.js +4 -4
  3. package/dist/node_modules/@bull-board/api/dist/src/handlers/error.d.ts +4 -2
  4. package/dist/node_modules/@bull-board/api/dist/src/handlers/error.js +2 -2
  5. package/dist/node_modules/@bull-board/api/dist/src/handlers/pauseAll.d.ts +4 -0
  6. package/dist/node_modules/@bull-board/api/dist/src/handlers/pauseAll.js +15 -0
  7. package/dist/node_modules/@bull-board/api/dist/src/handlers/queues.js +4 -0
  8. package/dist/node_modules/@bull-board/api/dist/src/handlers/resumeAll.d.ts +4 -0
  9. package/dist/node_modules/@bull-board/api/dist/src/handlers/resumeAll.js +15 -0
  10. package/dist/node_modules/@bull-board/api/dist/src/index.js +1 -1
  11. package/dist/node_modules/@bull-board/api/dist/src/queueAdapters/base.d.ts +4 -0
  12. package/dist/node_modules/@bull-board/api/dist/src/queueAdapters/base.js +6 -0
  13. package/dist/node_modules/@bull-board/api/dist/src/queueAdapters/bull.js +6 -4
  14. package/dist/node_modules/@bull-board/api/dist/src/routes.js +4 -0
  15. package/dist/node_modules/@bull-board/api/dist/typings/app.d.ts +22 -2
  16. package/dist/node_modules/@bull-board/api/package.json +1 -1
  17. package/dist/node_modules/@bull-board/koa/dist/KoaAdapter.js +1 -1
  18. package/dist/node_modules/@bull-board/koa/dist/index.js +101 -101
  19. package/dist/node_modules/@bull-board/koa/package.json +1 -1
  20. package/dist/node_modules/bullmq/dist/cjs/classes/backoffs.js +18 -5
  21. package/dist/node_modules/bullmq/dist/cjs/classes/child-pool.js +7 -2
  22. package/dist/node_modules/bullmq/dist/cjs/classes/child-processor.js +59 -5
  23. package/dist/node_modules/bullmq/dist/cjs/classes/child.js +3 -1
  24. package/dist/node_modules/bullmq/dist/cjs/classes/errors/index.js +2 -1
  25. package/dist/node_modules/bullmq/dist/cjs/classes/errors/waiting-error.js +19 -0
  26. package/dist/node_modules/bullmq/dist/cjs/classes/flow-producer.js +21 -5
  27. package/dist/node_modules/bullmq/dist/cjs/classes/index.js +1 -0
  28. package/dist/node_modules/bullmq/dist/cjs/classes/job-scheduler.js +88 -62
  29. package/dist/node_modules/bullmq/dist/cjs/classes/job.js +216 -109
  30. package/dist/node_modules/bullmq/dist/cjs/classes/main-base.js +1 -1
  31. package/dist/node_modules/bullmq/dist/cjs/classes/queue-base.js +10 -9
  32. package/dist/node_modules/bullmq/dist/cjs/classes/queue-getters.js +34 -14
  33. package/dist/node_modules/bullmq/dist/cjs/classes/queue.js +19 -13
  34. package/dist/node_modules/bullmq/dist/cjs/classes/redis-connection.js +16 -9
  35. package/dist/node_modules/bullmq/dist/cjs/classes/repeat.js +1 -1
  36. package/dist/node_modules/bullmq/dist/cjs/classes/sandbox.js +54 -28
  37. package/dist/node_modules/bullmq/dist/cjs/classes/scripts.js +141 -39
  38. package/dist/node_modules/bullmq/dist/cjs/classes/worker.js +191 -182
  39. package/dist/node_modules/bullmq/dist/cjs/commands/addDelayedJob-6.lua +6 -17
  40. package/dist/node_modules/bullmq/dist/cjs/commands/addJobScheduler-11.lua +123 -0
  41. package/dist/node_modules/bullmq/dist/{esm/commands/addParentJob-4.lua → cjs/commands/addParentJob-5.lua} +7 -6
  42. package/dist/node_modules/bullmq/dist/cjs/commands/{addPrioritizedJob-8.lua → addPrioritizedJob-9.lua} +11 -10
  43. package/dist/node_modules/bullmq/dist/cjs/commands/addRepeatableJob-2.lua +2 -2
  44. package/dist/node_modules/bullmq/dist/{esm/commands/addStandardJob-8.lua → cjs/commands/addStandardJob-9.lua} +9 -8
  45. package/dist/node_modules/bullmq/dist/cjs/commands/cleanJobsInSet-3.lua +9 -5
  46. package/dist/node_modules/bullmq/dist/cjs/commands/drain-5.lua +16 -16
  47. package/dist/node_modules/bullmq/dist/cjs/commands/getDependencyCounts-4.lua +31 -0
  48. package/dist/node_modules/bullmq/dist/cjs/commands/getState-8.lua +5 -5
  49. package/dist/node_modules/bullmq/dist/cjs/commands/getStateV2-8.lua +8 -8
  50. package/dist/node_modules/bullmq/dist/cjs/commands/includes/addDelayedJob.lua +23 -0
  51. package/dist/node_modules/bullmq/dist/cjs/commands/includes/addJobFromScheduler.lua +37 -0
  52. package/dist/node_modules/bullmq/dist/cjs/commands/includes/addJobWithPriority.lua +2 -2
  53. package/dist/node_modules/bullmq/dist/cjs/commands/includes/cleanList.lua +4 -2
  54. package/dist/node_modules/bullmq/dist/cjs/commands/includes/cleanSet.lua +3 -11
  55. package/dist/node_modules/bullmq/dist/cjs/commands/includes/collectMetrics.lua +1 -1
  56. package/dist/node_modules/bullmq/dist/cjs/commands/includes/deduplicateJob.lua +63 -18
  57. package/dist/node_modules/bullmq/dist/cjs/commands/includes/filterOutJobsToIgnore.lua +14 -0
  58. package/dist/node_modules/bullmq/dist/cjs/commands/includes/getNextDelayedTimestamp.lua +1 -1
  59. package/dist/node_modules/bullmq/dist/cjs/commands/includes/getOrSetMaxEvents.lua +6 -6
  60. package/dist/node_modules/bullmq/dist/cjs/commands/includes/getPriorityScore.lua +8 -0
  61. package/dist/node_modules/bullmq/dist/cjs/commands/includes/isJobSchedulerJob.lua +15 -0
  62. package/dist/node_modules/bullmq/dist/cjs/commands/includes/isLocked.lua +1 -0
  63. package/dist/node_modules/bullmq/dist/cjs/commands/includes/moveChildFromDependenciesIfNeeded.lua +77 -0
  64. package/dist/node_modules/bullmq/dist/cjs/commands/includes/{moveJobFromPriorityToActive.lua → moveJobFromPrioritizedToActive.lua} +1 -1
  65. package/dist/node_modules/bullmq/dist/cjs/commands/includes/moveParentToWait.lua +45 -0
  66. package/dist/node_modules/bullmq/dist/cjs/commands/includes/moveParentToWaitIfNeeded.lua +9 -50
  67. package/dist/node_modules/bullmq/dist/cjs/commands/includes/moveParentToWaitIfNoPendingDependencies.lua +13 -0
  68. package/dist/node_modules/bullmq/dist/cjs/commands/includes/prepareJobForProcessing.lua +2 -1
  69. package/dist/node_modules/bullmq/dist/cjs/commands/includes/promoteDelayedJobs.lua +7 -3
  70. package/dist/node_modules/bullmq/dist/cjs/commands/includes/removeDeduplicationKeyIfNeededOnFinalization.lua +23 -0
  71. package/dist/node_modules/bullmq/dist/cjs/commands/includes/removeDeduplicationKeyIfNeededOnRemoval.lua +16 -0
  72. package/dist/node_modules/bullmq/dist/cjs/commands/includes/removeJob.lua +2 -2
  73. package/dist/node_modules/bullmq/dist/cjs/commands/includes/removeJobKeys.lua +2 -2
  74. package/dist/node_modules/bullmq/dist/cjs/commands/includes/removeJobWithChildren.lua +95 -0
  75. package/dist/node_modules/bullmq/dist/cjs/commands/includes/removeListJobs.lua +7 -1
  76. package/dist/node_modules/bullmq/dist/cjs/commands/includes/removeParentDependencyKey.lua +5 -5
  77. package/dist/node_modules/bullmq/dist/cjs/commands/includes/removeZSetJobs.lua +2 -8
  78. package/dist/node_modules/bullmq/dist/cjs/commands/includes/storeJob.lua +2 -2
  79. package/dist/node_modules/bullmq/dist/cjs/commands/includes/storeJobScheduler.lua +52 -0
  80. package/dist/node_modules/bullmq/dist/cjs/commands/includes/trimEvents.lua +1 -1
  81. package/dist/node_modules/bullmq/dist/cjs/commands/includes/updateExistingJobsParent.lua +1 -1
  82. package/dist/node_modules/bullmq/dist/cjs/commands/includes/updateJobFields.lua +5 -5
  83. package/dist/node_modules/bullmq/dist/cjs/commands/includes/updateParentDepsIfNeeded.lua +2 -2
  84. package/dist/node_modules/bullmq/dist/cjs/commands/isFinished-3.lua +2 -2
  85. package/dist/node_modules/bullmq/dist/cjs/commands/moveJobFromActiveToWait-9.lua +63 -0
  86. package/dist/node_modules/bullmq/dist/cjs/commands/moveStalledJobsToWait-8.lua +109 -0
  87. package/dist/node_modules/bullmq/dist/cjs/commands/moveToActive-11.lua +3 -2
  88. package/dist/node_modules/bullmq/dist/cjs/commands/moveToFinished-14.lua +52 -52
  89. package/dist/node_modules/bullmq/dist/cjs/commands/moveToWaitingChildren-8.lua +106 -0
  90. package/dist/node_modules/bullmq/dist/cjs/commands/removeJob-2.lua +18 -66
  91. package/dist/node_modules/bullmq/dist/cjs/commands/removeJobScheduler-3.lua +1 -1
  92. package/dist/node_modules/bullmq/dist/cjs/commands/removeUnprocessedChildren-2.lua +31 -0
  93. package/dist/node_modules/bullmq/dist/cjs/commands/retryJob-11.lua +11 -5
  94. package/dist/node_modules/bullmq/dist/cjs/commands/updateJobScheduler-12.lua +90 -0
  95. package/dist/node_modules/bullmq/dist/cjs/commands/updateRepeatableJobMillis-1.lua +1 -1
  96. package/dist/node_modules/bullmq/dist/cjs/enums/child-command.js +2 -0
  97. package/dist/node_modules/bullmq/dist/cjs/enums/error-code.js +2 -1
  98. package/dist/node_modules/bullmq/dist/cjs/enums/parent-command.js +5 -2
  99. package/dist/node_modules/bullmq/dist/cjs/index.js +1 -1
  100. package/dist/node_modules/bullmq/dist/cjs/interfaces/index.js +2 -1
  101. package/dist/node_modules/bullmq/dist/cjs/interfaces/{debounce-options.js → parent-options.js} +1 -1
  102. package/dist/node_modules/bullmq/dist/cjs/interfaces/receiver.js +3 -0
  103. package/dist/node_modules/bullmq/dist/cjs/scripts/addDelayedJob-6.js +163 -84
  104. package/dist/node_modules/bullmq/dist/cjs/scripts/addJobScheduler-11.js +465 -0
  105. package/dist/node_modules/bullmq/dist/cjs/scripts/{addParentJob-4.js → addParentJob-5.js} +147 -75
  106. package/dist/node_modules/bullmq/dist/cjs/scripts/{addPrioritizedJob-8.js → addPrioritizedJob-9.js} +151 -79
  107. package/dist/node_modules/bullmq/dist/cjs/scripts/addRepeatableJob-2.js +18 -13
  108. package/dist/node_modules/bullmq/dist/cjs/scripts/{addStandardJob-8.js → addStandardJob-9.js} +149 -77
  109. package/dist/node_modules/bullmq/dist/cjs/scripts/changeDelay-4.js +7 -7
  110. package/dist/node_modules/bullmq/dist/cjs/scripts/changePriority-7.js +8 -2
  111. package/dist/node_modules/bullmq/dist/cjs/scripts/cleanJobsInSet-3.js +45 -29
  112. package/dist/node_modules/bullmq/dist/cjs/scripts/drain-5.js +49 -35
  113. package/dist/node_modules/bullmq/dist/cjs/scripts/getDependencyCounts-4.js +37 -0
  114. package/dist/node_modules/bullmq/dist/cjs/scripts/getState-8.js +5 -5
  115. package/dist/node_modules/bullmq/dist/cjs/scripts/getStateV2-8.js +8 -8
  116. package/dist/node_modules/bullmq/dist/cjs/scripts/index.js +10 -7
  117. package/dist/node_modules/bullmq/dist/cjs/scripts/isFinished-3.js +2 -2
  118. package/dist/node_modules/bullmq/dist/cjs/scripts/{moveJobFromActiveToWait-10.js → moveJobFromActiveToWait-9.js} +57 -37
  119. package/dist/node_modules/bullmq/dist/cjs/scripts/moveJobsToWait-8.js +6 -6
  120. package/dist/node_modules/bullmq/dist/cjs/scripts/moveStalledJobsToWait-8.js +171 -0
  121. package/dist/node_modules/bullmq/dist/cjs/scripts/moveToActive-11.js +18 -8
  122. package/dist/node_modules/bullmq/dist/cjs/scripts/moveToDelayed-8.js +12 -12
  123. package/dist/node_modules/bullmq/dist/cjs/scripts/moveToFinished-14.js +218 -155
  124. package/dist/node_modules/bullmq/dist/cjs/scripts/moveToWaitingChildren-8.js +529 -0
  125. package/dist/node_modules/bullmq/dist/cjs/scripts/obliterate-2.js +33 -20
  126. package/dist/node_modules/bullmq/dist/cjs/scripts/pause-7.js +1 -1
  127. package/dist/node_modules/bullmq/dist/cjs/scripts/promote-9.js +8 -2
  128. package/dist/node_modules/bullmq/dist/cjs/scripts/removeChildDependency-1.js +7 -7
  129. package/dist/node_modules/bullmq/dist/cjs/scripts/removeJob-2.js +120 -63
  130. package/dist/node_modules/bullmq/dist/cjs/scripts/removeJobScheduler-3.js +3 -3
  131. package/dist/node_modules/bullmq/dist/cjs/scripts/removeRepeatable-3.js +2 -2
  132. package/dist/node_modules/bullmq/dist/cjs/scripts/removeUnprocessedChildren-2.js +339 -0
  133. package/dist/node_modules/bullmq/dist/cjs/scripts/reprocessJob-8.js +6 -6
  134. package/dist/node_modules/bullmq/dist/cjs/scripts/retryJob-11.js +47 -26
  135. package/dist/node_modules/bullmq/dist/cjs/scripts/updateJobScheduler-12.js +274 -0
  136. package/dist/node_modules/bullmq/dist/cjs/scripts/updateProgress-3.js +6 -6
  137. package/dist/node_modules/bullmq/dist/cjs/scripts/updateRepeatableJobMillis-1.js +1 -1
  138. package/dist/node_modules/bullmq/dist/cjs/tsconfig-cjs.tsbuildinfo +1 -1
  139. package/dist/node_modules/bullmq/dist/cjs/types/deduplication-options.js +3 -0
  140. package/dist/node_modules/bullmq/dist/cjs/types/index.js +3 -0
  141. package/dist/node_modules/bullmq/dist/cjs/types/job-progress.js +3 -0
  142. package/dist/node_modules/bullmq/dist/cjs/types/script-queue-context.js +3 -0
  143. package/dist/node_modules/bullmq/dist/cjs/utils.js +29 -1
  144. package/dist/node_modules/bullmq/dist/cjs/version.js +1 -1
  145. package/dist/node_modules/bullmq/dist/esm/classes/backoffs.d.ts +1 -1
  146. package/dist/node_modules/bullmq/dist/esm/classes/backoffs.js +18 -5
  147. package/dist/node_modules/bullmq/dist/esm/classes/child-pool.d.ts +1 -1
  148. package/dist/node_modules/bullmq/dist/esm/classes/child-pool.js +7 -2
  149. package/dist/node_modules/bullmq/dist/esm/classes/child-processor.d.ts +3 -2
  150. package/dist/node_modules/bullmq/dist/esm/classes/child-processor.js +59 -5
  151. package/dist/node_modules/bullmq/dist/esm/classes/child.js +3 -1
  152. package/dist/node_modules/bullmq/dist/esm/classes/errors/index.d.ts +2 -1
  153. package/dist/node_modules/bullmq/dist/esm/classes/errors/index.js +2 -1
  154. package/dist/node_modules/bullmq/dist/esm/classes/errors/waiting-error.d.ts +10 -0
  155. package/dist/node_modules/bullmq/dist/esm/classes/errors/waiting-error.js +15 -0
  156. package/dist/node_modules/bullmq/dist/esm/classes/flow-producer.d.ts +3 -9
  157. package/dist/node_modules/bullmq/dist/esm/classes/flow-producer.js +21 -5
  158. package/dist/node_modules/bullmq/dist/esm/classes/index.d.ts +1 -0
  159. package/dist/node_modules/bullmq/dist/esm/classes/index.js +1 -0
  160. package/dist/node_modules/bullmq/dist/esm/classes/job-scheduler.d.ts +2 -2
  161. package/dist/node_modules/bullmq/dist/esm/classes/job-scheduler.js +88 -62
  162. package/dist/node_modules/bullmq/dist/esm/classes/job.d.ts +69 -19
  163. package/dist/node_modules/bullmq/dist/esm/classes/job.js +217 -110
  164. package/dist/node_modules/bullmq/dist/esm/classes/main-base.d.ts +2 -3
  165. package/dist/node_modules/bullmq/dist/esm/classes/main-base.js +1 -1
  166. package/dist/node_modules/bullmq/dist/esm/classes/queue-base.d.ts +2 -5
  167. package/dist/node_modules/bullmq/dist/esm/classes/queue-base.js +11 -10
  168. package/dist/node_modules/bullmq/dist/esm/classes/queue-events-producer.d.ts +2 -2
  169. package/dist/node_modules/bullmq/dist/esm/classes/queue-events.d.ts +118 -29
  170. package/dist/node_modules/bullmq/dist/esm/classes/queue-getters.d.ts +20 -13
  171. package/dist/node_modules/bullmq/dist/esm/classes/queue-getters.js +34 -14
  172. package/dist/node_modules/bullmq/dist/esm/classes/queue.d.ts +19 -16
  173. package/dist/node_modules/bullmq/dist/esm/classes/queue.js +19 -13
  174. package/dist/node_modules/bullmq/dist/esm/classes/redis-connection.d.ts +7 -3
  175. package/dist/node_modules/bullmq/dist/esm/classes/redis-connection.js +16 -9
  176. package/dist/node_modules/bullmq/dist/esm/classes/repeat.js +1 -1
  177. package/dist/node_modules/bullmq/dist/esm/classes/sandbox.js +54 -28
  178. package/dist/node_modules/bullmq/dist/esm/classes/scripts.d.ts +20 -13
  179. package/dist/node_modules/bullmq/dist/esm/classes/scripts.js +141 -39
  180. package/dist/node_modules/bullmq/dist/esm/classes/worker.d.ts +28 -7
  181. package/dist/node_modules/bullmq/dist/esm/classes/worker.js +192 -183
  182. package/dist/node_modules/bullmq/dist/esm/commands/addDelayedJob-6.lua +6 -17
  183. package/dist/node_modules/bullmq/dist/esm/commands/addJobScheduler-11.lua +123 -0
  184. package/dist/node_modules/bullmq/dist/{cjs/commands/addParentJob-4.lua → esm/commands/addParentJob-5.lua} +7 -6
  185. package/dist/node_modules/bullmq/dist/esm/commands/{addPrioritizedJob-8.lua → addPrioritizedJob-9.lua} +11 -10
  186. package/dist/node_modules/bullmq/dist/esm/commands/addRepeatableJob-2.lua +2 -2
  187. package/dist/node_modules/bullmq/dist/{cjs/commands/addStandardJob-8.lua → esm/commands/addStandardJob-9.lua} +9 -8
  188. package/dist/node_modules/bullmq/dist/esm/commands/cleanJobsInSet-3.lua +9 -5
  189. package/dist/node_modules/bullmq/dist/esm/commands/drain-5.lua +16 -16
  190. package/dist/node_modules/bullmq/dist/esm/commands/getDependencyCounts-4.lua +31 -0
  191. package/dist/node_modules/bullmq/dist/esm/commands/getState-8.lua +5 -5
  192. package/dist/node_modules/bullmq/dist/esm/commands/getStateV2-8.lua +8 -8
  193. package/dist/node_modules/bullmq/dist/esm/commands/includes/addDelayedJob.lua +23 -0
  194. package/dist/node_modules/bullmq/dist/esm/commands/includes/addJobFromScheduler.lua +37 -0
  195. package/dist/node_modules/bullmq/dist/esm/commands/includes/addJobWithPriority.lua +2 -2
  196. package/dist/node_modules/bullmq/dist/esm/commands/includes/cleanList.lua +4 -2
  197. package/dist/node_modules/bullmq/dist/esm/commands/includes/cleanSet.lua +3 -11
  198. package/dist/node_modules/bullmq/dist/esm/commands/includes/collectMetrics.lua +1 -1
  199. package/dist/node_modules/bullmq/dist/esm/commands/includes/deduplicateJob.lua +63 -18
  200. package/dist/node_modules/bullmq/dist/esm/commands/includes/filterOutJobsToIgnore.lua +14 -0
  201. package/dist/node_modules/bullmq/dist/esm/commands/includes/getNextDelayedTimestamp.lua +1 -1
  202. package/dist/node_modules/bullmq/dist/esm/commands/includes/getOrSetMaxEvents.lua +6 -6
  203. package/dist/node_modules/bullmq/dist/esm/commands/includes/getPriorityScore.lua +8 -0
  204. package/dist/node_modules/bullmq/dist/esm/commands/includes/isJobSchedulerJob.lua +15 -0
  205. package/dist/node_modules/bullmq/dist/esm/commands/includes/isLocked.lua +1 -0
  206. package/dist/node_modules/bullmq/dist/esm/commands/includes/moveChildFromDependenciesIfNeeded.lua +77 -0
  207. package/dist/node_modules/bullmq/dist/esm/commands/includes/{moveJobFromPriorityToActive.lua → moveJobFromPrioritizedToActive.lua} +1 -1
  208. package/dist/node_modules/bullmq/dist/esm/commands/includes/moveParentToWait.lua +45 -0
  209. package/dist/node_modules/bullmq/dist/esm/commands/includes/moveParentToWaitIfNeeded.lua +9 -50
  210. package/dist/node_modules/bullmq/dist/esm/commands/includes/moveParentToWaitIfNoPendingDependencies.lua +13 -0
  211. package/dist/node_modules/bullmq/dist/esm/commands/includes/prepareJobForProcessing.lua +2 -1
  212. package/dist/node_modules/bullmq/dist/esm/commands/includes/promoteDelayedJobs.lua +7 -3
  213. package/dist/node_modules/bullmq/dist/esm/commands/includes/removeDeduplicationKeyIfNeededOnFinalization.lua +23 -0
  214. package/dist/node_modules/bullmq/dist/esm/commands/includes/removeDeduplicationKeyIfNeededOnRemoval.lua +16 -0
  215. package/dist/node_modules/bullmq/dist/esm/commands/includes/removeJob.lua +2 -2
  216. package/dist/node_modules/bullmq/dist/esm/commands/includes/removeJobKeys.lua +2 -2
  217. package/dist/node_modules/bullmq/dist/esm/commands/includes/removeJobWithChildren.lua +95 -0
  218. package/dist/node_modules/bullmq/dist/esm/commands/includes/removeListJobs.lua +7 -1
  219. package/dist/node_modules/bullmq/dist/esm/commands/includes/removeParentDependencyKey.lua +5 -5
  220. package/dist/node_modules/bullmq/dist/esm/commands/includes/removeZSetJobs.lua +2 -8
  221. package/dist/node_modules/bullmq/dist/esm/commands/includes/storeJob.lua +2 -2
  222. package/dist/node_modules/bullmq/dist/esm/commands/includes/storeJobScheduler.lua +52 -0
  223. package/dist/node_modules/bullmq/dist/esm/commands/includes/trimEvents.lua +1 -1
  224. package/dist/node_modules/bullmq/dist/esm/commands/includes/updateExistingJobsParent.lua +1 -1
  225. package/dist/node_modules/bullmq/dist/esm/commands/includes/updateJobFields.lua +5 -5
  226. package/dist/node_modules/bullmq/dist/esm/commands/includes/updateParentDepsIfNeeded.lua +2 -2
  227. package/dist/node_modules/bullmq/dist/esm/commands/isFinished-3.lua +2 -2
  228. package/dist/node_modules/bullmq/dist/esm/commands/moveJobFromActiveToWait-9.lua +63 -0
  229. package/dist/node_modules/bullmq/dist/esm/commands/moveStalledJobsToWait-8.lua +109 -0
  230. package/dist/node_modules/bullmq/dist/esm/commands/moveToActive-11.lua +3 -2
  231. package/dist/node_modules/bullmq/dist/esm/commands/moveToFinished-14.lua +52 -52
  232. package/dist/node_modules/bullmq/dist/esm/commands/moveToWaitingChildren-8.lua +106 -0
  233. package/dist/node_modules/bullmq/dist/esm/commands/removeJob-2.lua +18 -66
  234. package/dist/node_modules/bullmq/dist/esm/commands/removeJobScheduler-3.lua +1 -1
  235. package/dist/node_modules/bullmq/dist/esm/commands/removeUnprocessedChildren-2.lua +31 -0
  236. package/dist/node_modules/bullmq/dist/esm/commands/retryJob-11.lua +11 -5
  237. package/dist/node_modules/bullmq/dist/esm/commands/updateJobScheduler-12.lua +90 -0
  238. package/dist/node_modules/bullmq/dist/esm/commands/updateRepeatableJobMillis-1.lua +1 -1
  239. package/dist/node_modules/bullmq/dist/esm/enums/child-command.d.ts +3 -1
  240. package/dist/node_modules/bullmq/dist/esm/enums/child-command.js +2 -0
  241. package/dist/node_modules/bullmq/dist/esm/enums/error-code.d.ts +3 -2
  242. package/dist/node_modules/bullmq/dist/esm/enums/error-code.js +2 -1
  243. package/dist/node_modules/bullmq/dist/esm/enums/parent-command.d.ts +5 -2
  244. package/dist/node_modules/bullmq/dist/esm/enums/parent-command.js +5 -2
  245. package/dist/node_modules/bullmq/dist/esm/interfaces/backoff-options.d.ts +5 -0
  246. package/dist/node_modules/bullmq/dist/esm/interfaces/base-job-options.d.ts +3 -9
  247. package/dist/node_modules/bullmq/dist/esm/interfaces/child-message.d.ts +1 -0
  248. package/dist/node_modules/bullmq/dist/esm/interfaces/index.d.ts +2 -1
  249. package/dist/node_modules/bullmq/dist/esm/interfaces/index.js +2 -1
  250. package/dist/node_modules/bullmq/dist/esm/interfaces/job-json.d.ts +6 -2
  251. package/dist/node_modules/bullmq/dist/esm/interfaces/job-scheduler-json.d.ts +7 -4
  252. package/dist/node_modules/bullmq/dist/esm/interfaces/minimal-job.d.ts +34 -15
  253. package/dist/node_modules/bullmq/dist/esm/interfaces/parent-options.d.ts +11 -0
  254. package/dist/node_modules/bullmq/dist/esm/interfaces/parent-options.js +2 -0
  255. package/dist/node_modules/bullmq/dist/esm/interfaces/parent.d.ts +6 -2
  256. package/dist/node_modules/bullmq/dist/esm/interfaces/queue-options.d.ts +15 -6
  257. package/dist/node_modules/bullmq/dist/esm/interfaces/receiver.d.ts +4 -0
  258. package/dist/node_modules/bullmq/dist/esm/interfaces/receiver.js +2 -0
  259. package/dist/node_modules/bullmq/dist/esm/interfaces/repeat-options.d.ts +1 -2
  260. package/dist/node_modules/bullmq/dist/esm/interfaces/repeatable-options.d.ts +2 -0
  261. package/dist/node_modules/bullmq/dist/esm/interfaces/sandboxed-job.d.ts +3 -2
  262. package/dist/node_modules/bullmq/dist/esm/interfaces/sandboxed-options.d.ts +1 -1
  263. package/dist/node_modules/bullmq/dist/esm/interfaces/telemetry.d.ts +18 -15
  264. package/dist/node_modules/bullmq/dist/esm/interfaces/worker-options.d.ts +10 -10
  265. package/dist/node_modules/bullmq/dist/esm/scripts/addDelayedJob-6.js +163 -84
  266. package/dist/node_modules/bullmq/dist/esm/scripts/addJobScheduler-11.js +462 -0
  267. package/dist/node_modules/bullmq/dist/esm/scripts/{addParentJob-4.js → addParentJob-5.js} +147 -75
  268. package/dist/node_modules/bullmq/dist/esm/scripts/{addPrioritizedJob-8.js → addPrioritizedJob-9.js} +151 -79
  269. package/dist/node_modules/bullmq/dist/esm/scripts/addRepeatableJob-2.js +18 -13
  270. package/dist/node_modules/bullmq/dist/esm/scripts/{addStandardJob-8.js → addStandardJob-9.js} +149 -77
  271. package/dist/node_modules/bullmq/dist/esm/scripts/changeDelay-4.js +7 -7
  272. package/dist/node_modules/bullmq/dist/esm/scripts/changePriority-7.js +8 -2
  273. package/dist/node_modules/bullmq/dist/esm/scripts/cleanJobsInSet-3.js +45 -29
  274. package/dist/node_modules/bullmq/dist/esm/scripts/drain-5.js +49 -35
  275. package/dist/node_modules/bullmq/dist/esm/scripts/getDependencyCounts-4.d.ts +5 -0
  276. package/dist/node_modules/bullmq/dist/esm/scripts/getDependencyCounts-4.js +34 -0
  277. package/dist/node_modules/bullmq/dist/esm/scripts/getState-8.js +5 -5
  278. package/dist/node_modules/bullmq/dist/esm/scripts/getStateV2-8.js +8 -8
  279. package/dist/node_modules/bullmq/dist/esm/scripts/index.d.ts +10 -7
  280. package/dist/node_modules/bullmq/dist/esm/scripts/index.js +10 -7
  281. package/dist/node_modules/bullmq/dist/esm/scripts/isFinished-3.js +2 -2
  282. package/dist/node_modules/bullmq/dist/esm/scripts/{moveJobFromActiveToWait-10.js → moveJobFromActiveToWait-9.js} +57 -37
  283. package/dist/node_modules/bullmq/dist/esm/scripts/moveJobsToWait-8.js +6 -6
  284. package/dist/node_modules/bullmq/dist/esm/scripts/moveStalledJobsToWait-8.js +168 -0
  285. package/dist/node_modules/bullmq/dist/esm/scripts/moveToActive-11.js +18 -8
  286. package/dist/node_modules/bullmq/dist/esm/scripts/moveToDelayed-8.js +12 -12
  287. package/dist/node_modules/bullmq/dist/esm/scripts/moveToFinished-14.js +218 -155
  288. package/dist/node_modules/bullmq/dist/esm/scripts/moveToWaitingChildren-8.js +526 -0
  289. package/dist/node_modules/bullmq/dist/esm/scripts/obliterate-2.js +33 -20
  290. package/dist/node_modules/bullmq/dist/esm/scripts/pause-7.js +1 -1
  291. package/dist/node_modules/bullmq/dist/esm/scripts/promote-9.js +8 -2
  292. package/dist/node_modules/bullmq/dist/esm/scripts/removeChildDependency-1.js +7 -7
  293. package/dist/node_modules/bullmq/dist/esm/scripts/removeJob-2.js +120 -63
  294. package/dist/node_modules/bullmq/dist/esm/scripts/removeJobScheduler-3.js +3 -3
  295. package/dist/node_modules/bullmq/dist/esm/scripts/removeRepeatable-3.js +2 -2
  296. package/dist/node_modules/bullmq/dist/esm/scripts/removeUnprocessedChildren-2.d.ts +5 -0
  297. package/dist/node_modules/bullmq/dist/esm/scripts/removeUnprocessedChildren-2.js +336 -0
  298. package/dist/node_modules/bullmq/dist/esm/scripts/reprocessJob-8.js +6 -6
  299. package/dist/node_modules/bullmq/dist/esm/scripts/retryJob-11.js +47 -26
  300. package/dist/node_modules/bullmq/dist/esm/scripts/updateJobScheduler-12.d.ts +5 -0
  301. package/dist/node_modules/bullmq/dist/esm/scripts/updateJobScheduler-12.js +271 -0
  302. package/dist/node_modules/bullmq/dist/esm/scripts/updateProgress-3.js +6 -6
  303. package/dist/node_modules/bullmq/dist/esm/scripts/updateRepeatableJobMillis-1.js +1 -1
  304. package/dist/node_modules/bullmq/dist/esm/tsconfig.tsbuildinfo +1 -1
  305. package/dist/node_modules/bullmq/dist/esm/types/deduplication-options.d.ts +22 -0
  306. package/dist/node_modules/bullmq/dist/esm/types/deduplication-options.js +2 -0
  307. package/dist/node_modules/bullmq/dist/esm/types/index.d.ts +3 -0
  308. package/dist/node_modules/bullmq/dist/esm/types/index.js +3 -0
  309. package/dist/node_modules/bullmq/dist/esm/types/job-options.d.ts +19 -8
  310. package/dist/node_modules/bullmq/dist/esm/types/job-progress.d.ts +1 -0
  311. package/dist/node_modules/bullmq/dist/esm/types/job-progress.js +2 -0
  312. package/dist/node_modules/bullmq/dist/esm/types/script-queue-context.d.ts +2 -0
  313. package/dist/node_modules/bullmq/dist/esm/types/script-queue-context.js +2 -0
  314. package/dist/node_modules/bullmq/dist/esm/utils.d.ts +25 -5
  315. package/dist/node_modules/bullmq/dist/esm/utils.js +27 -0
  316. package/dist/node_modules/bullmq/dist/esm/version.d.ts +1 -1
  317. package/dist/node_modules/bullmq/dist/esm/version.js +1 -1
  318. package/dist/node_modules/bullmq/package.json +1 -1
  319. package/package.json +7 -7
  320. package/dist/node_modules/bullmq/dist/cjs/commands/addJobScheduler-2.lua +0 -91
  321. package/dist/node_modules/bullmq/dist/cjs/commands/includes/moveParentFromWaitingChildrenToFailed.lua +0 -53
  322. package/dist/node_modules/bullmq/dist/cjs/commands/includes/removeDeduplicationKey.lua +0 -11
  323. package/dist/node_modules/bullmq/dist/cjs/commands/includes/removeDeduplicationKeyIfNeeded.lua +0 -14
  324. package/dist/node_modules/bullmq/dist/cjs/commands/moveJobFromActiveToWait-10.lua +0 -60
  325. package/dist/node_modules/bullmq/dist/cjs/commands/moveStalledJobsToWait-9.lua +0 -156
  326. package/dist/node_modules/bullmq/dist/cjs/commands/moveToWaitingChildren-5.lua +0 -68
  327. package/dist/node_modules/bullmq/dist/cjs/scripts/addJobScheduler-2.js +0 -237
  328. package/dist/node_modules/bullmq/dist/cjs/scripts/moveStalledJobsToWait-9.js +0 -529
  329. package/dist/node_modules/bullmq/dist/cjs/scripts/moveToWaitingChildren-5.js +0 -83
  330. package/dist/node_modules/bullmq/dist/esm/commands/addJobScheduler-2.lua +0 -91
  331. package/dist/node_modules/bullmq/dist/esm/commands/includes/moveParentFromWaitingChildrenToFailed.lua +0 -53
  332. package/dist/node_modules/bullmq/dist/esm/commands/includes/removeDeduplicationKey.lua +0 -11
  333. package/dist/node_modules/bullmq/dist/esm/commands/includes/removeDeduplicationKeyIfNeeded.lua +0 -14
  334. package/dist/node_modules/bullmq/dist/esm/commands/moveJobFromActiveToWait-10.lua +0 -60
  335. package/dist/node_modules/bullmq/dist/esm/commands/moveStalledJobsToWait-9.lua +0 -156
  336. package/dist/node_modules/bullmq/dist/esm/commands/moveToWaitingChildren-5.lua +0 -68
  337. package/dist/node_modules/bullmq/dist/esm/interfaces/debounce-options.d.ts +0 -13
  338. package/dist/node_modules/bullmq/dist/esm/interfaces/debounce-options.js +0 -2
  339. package/dist/node_modules/bullmq/dist/esm/scripts/addJobScheduler-2.js +0 -234
  340. package/dist/node_modules/bullmq/dist/esm/scripts/moveStalledJobsToWait-9.js +0 -526
  341. package/dist/node_modules/bullmq/dist/esm/scripts/moveToWaitingChildren-5.js +0 -80
  342. /package/dist/node_modules/bullmq/dist/esm/scripts/{addJobScheduler-2.d.ts → addJobScheduler-11.d.ts} +0 -0
  343. /package/dist/node_modules/bullmq/dist/esm/scripts/{addParentJob-4.d.ts → addParentJob-5.d.ts} +0 -0
  344. /package/dist/node_modules/bullmq/dist/esm/scripts/{addPrioritizedJob-8.d.ts → addPrioritizedJob-9.d.ts} +0 -0
  345. /package/dist/node_modules/bullmq/dist/esm/scripts/{addStandardJob-8.d.ts → addStandardJob-9.d.ts} +0 -0
  346. /package/dist/node_modules/bullmq/dist/esm/scripts/{moveJobFromActiveToWait-10.d.ts → moveJobFromActiveToWait-9.d.ts} +0 -0
  347. /package/dist/node_modules/bullmq/dist/esm/scripts/{moveStalledJobsToWait-9.d.ts → moveStalledJobsToWait-8.d.ts} +0 -0
  348. /package/dist/node_modules/bullmq/dist/esm/scripts/{moveToWaitingChildren-5.d.ts → moveToWaitingChildren-8.d.ts} +0 -0
@@ -8,17 +8,16 @@ import { delay, DELAY_TIME_1, isNotConnectionError, isRedisInstance, } from '../
8
8
  import { QueueBase } from './queue-base';
9
9
  import { Repeat } from './repeat';
10
10
  import { ChildPool } from './child-pool';
11
- import { Job } from './job';
12
11
  import { RedisConnection } from './redis-connection';
13
12
  import sandbox from './sandbox';
14
13
  import { AsyncFifoQueue } from './async-fifo-queue';
15
- import { DelayedError, RateLimitError, RATE_LIMIT_ERROR, WaitingChildrenError, } from './errors';
14
+ import { DelayedError, RateLimitError, RATE_LIMIT_ERROR, WaitingChildrenError, WaitingError, UnrecoverableError, } from './errors';
16
15
  import { SpanKind, TelemetryAttributes } from '../enums';
17
16
  import { JobScheduler } from './job-scheduler';
18
17
  // 10 seconds is the maximum time a BZPOPMIN can block.
19
18
  const maximumBlockTimeout = 10;
20
19
  // 30 seconds is the maximum limit until.
21
- const maximumLimitUntil = 30000;
20
+ const maximumRateLimitDelay = 30000;
22
21
  /**
23
22
  *
24
23
  * This class represents a worker that is able to process jobs from the queue.
@@ -31,7 +30,7 @@ export class Worker extends QueueBase {
31
30
  return new RateLimitError();
32
31
  }
33
32
  constructor(name, processor, opts, Connection) {
34
- super(name, Object.assign(Object.assign({}, opts), { blockingConnection: true }), Connection);
33
+ super(name, Object.assign(Object.assign({ drainDelay: 5, concurrency: 1, lockDuration: 30000, maxStalledCount: 1, stalledInterval: 30000, autorun: true, runRetryDelay: 15000 }, opts), { blockingConnection: true }), Connection);
35
34
  this.abortDelayController = null;
36
35
  this.blockUntil = 0;
37
36
  this.drained = false;
@@ -39,14 +38,19 @@ export class Worker extends QueueBase {
39
38
  this.limitUntil = 0;
40
39
  this.waiting = null;
41
40
  this.running = false;
41
+ this.mainLoopRunning = null;
42
42
  if (!opts || !opts.connection) {
43
43
  throw new Error('Worker requires a connection');
44
44
  }
45
- this.opts = Object.assign({ drainDelay: 5, concurrency: 1, lockDuration: 30000, maxStalledCount: 1, stalledInterval: 30000, autorun: true, runRetryDelay: 15000 }, this.opts);
46
- if (this.opts.stalledInterval <= 0) {
45
+ if (typeof this.opts.maxStalledCount !== 'number' ||
46
+ this.opts.maxStalledCount < 0) {
47
+ throw new Error('maxStalledCount must be greater or equal than 0');
48
+ }
49
+ if (typeof this.opts.stalledInterval !== 'number' ||
50
+ this.opts.stalledInterval <= 0) {
47
51
  throw new Error('stalledInterval must be greater than 0');
48
52
  }
49
- if (this.opts.drainDelay <= 0) {
53
+ if (typeof this.opts.drainDelay !== 'number' || this.opts.drainDelay <= 0) {
50
54
  throw new Error('drainDelay must be greater than 0');
51
55
  }
52
56
  this.concurrency = this.opts.concurrency;
@@ -105,7 +109,11 @@ export class Worker extends QueueBase {
105
109
  const connectionName = this.clientName() + (this.opts.name ? `:w:${this.opts.name}` : '');
106
110
  this.blockingConnection = new RedisConnection(isRedisInstance(opts.connection)
107
111
  ? opts.connection.duplicate({ connectionName })
108
- : Object.assign(Object.assign({}, opts.connection), { connectionName }), false, true, opts.skipVersionCheck);
112
+ : Object.assign(Object.assign({}, opts.connection), { connectionName }), {
113
+ shared: false,
114
+ blocking: true,
115
+ skipVersionCheck: opts.skipVersionCheck,
116
+ });
109
117
  this.blockingConnection.on('error', error => this.emit('error', error));
110
118
  this.blockingConnection.on('ready', () => setTimeout(() => this.emit('ready'), 0));
111
119
  }
@@ -180,70 +188,87 @@ export class Worker extends QueueBase {
180
188
  }
181
189
  try {
182
190
  this.running = true;
183
- if (this.closing) {
191
+ if (this.closing || this.paused) {
184
192
  return;
185
193
  }
186
194
  await this.startStalledCheckTimer();
187
- const jobsInProgress = new Set();
188
- this.startLockExtenderTimer(jobsInProgress);
189
- const asyncFifoQueue = (this.asyncFifoQueue =
190
- new AsyncFifoQueue());
191
- let tokenPostfix = 0;
192
195
  const client = await this.client;
193
196
  const bclient = await this.blockingConnection.client;
197
+ this.mainLoopRunning = this.mainLoop(client, bclient);
198
+ // We must await here or finally will be called too early.
199
+ await this.mainLoopRunning;
200
+ }
201
+ finally {
202
+ this.running = false;
203
+ }
204
+ }
205
+ async waitForRateLimit() {
206
+ var _a;
207
+ const limitUntil = this.limitUntil;
208
+ if (limitUntil > Date.now()) {
209
+ (_a = this.abortDelayController) === null || _a === void 0 ? void 0 : _a.abort();
210
+ this.abortDelayController = new AbortController();
211
+ const delay = this.getRateLimitDelay(limitUntil - Date.now());
212
+ await this.delay(delay, this.abortDelayController);
213
+ }
214
+ }
215
+ /**
216
+ * This is the main loop in BullMQ. Its goals are to fetch jobs from the queue
217
+ * as efficiently as possible, providing concurrency and minimal unnecessary calls
218
+ * to Redis.
219
+ */
220
+ async mainLoop(client, bclient) {
221
+ const asyncFifoQueue = new AsyncFifoQueue();
222
+ const jobsInProgress = new Set();
223
+ this.startLockExtenderTimer(jobsInProgress);
224
+ let tokenPostfix = 0;
225
+ while (!this.closing && !this.paused) {
226
+ let numTotal = asyncFifoQueue.numTotal();
194
227
  /**
195
- * This is the main loop in BullMQ. Its goals are to fetch jobs from the queue
196
- * as efficiently as possible, providing concurrency and minimal unnecessary calls
197
- * to Redis.
228
+ * This inner loop tries to fetch jobs concurrently, but if we are waiting for a job
229
+ * to arrive at the queue we should not try to fetch more jobs (as it would be pointless)
198
230
  */
199
- while (!this.closing) {
200
- let numTotal = asyncFifoQueue.numTotal();
201
- /**
202
- * This inner loop tries to fetch jobs concurrently, but if we are waiting for a job
203
- * to arrive at the queue we should not try to fetch more jobs (as it would be pointless)
204
- */
205
- while (!this.waiting &&
206
- numTotal < this._concurrency &&
207
- (!this.limitUntil || numTotal == 0)) {
208
- const token = `${this.id}:${tokenPostfix++}`;
209
- const fetchedJob = this.retryIfFailed(() => this._getNextJob(client, bclient, token, { block: true }), this.opts.runRetryDelay);
210
- asyncFifoQueue.add(fetchedJob);
211
- numTotal = asyncFifoQueue.numTotal();
212
- if (this.waiting && numTotal > 1) {
213
- // We are waiting for jobs but we have others that we could start processing already
214
- break;
215
- }
216
- // We await here so that we fetch jobs in sequence, this is important to avoid unnecessary calls
217
- // to Redis in high concurrency scenarios.
218
- const job = await fetchedJob;
219
- // No more jobs waiting but we have others that could start processing already
220
- if (!job && numTotal > 1) {
221
- break;
222
- }
223
- // If there are potential jobs to be processed and blockUntil is set, we should exit to avoid waiting
224
- // for processing this job.
225
- if (this.blockUntil) {
226
- break;
227
- }
231
+ while (!this.closing &&
232
+ !this.paused &&
233
+ !this.waiting &&
234
+ numTotal < this._concurrency &&
235
+ !this.isRateLimited()) {
236
+ const token = `${this.id}:${tokenPostfix++}`;
237
+ const fetchedJob = this.retryIfFailed(() => this._getNextJob(client, bclient, token, { block: true }), this.opts.runRetryDelay);
238
+ asyncFifoQueue.add(fetchedJob);
239
+ numTotal = asyncFifoQueue.numTotal();
240
+ if (this.waiting && numTotal > 1) {
241
+ // We are waiting for jobs but we have others that we could start processing already
242
+ break;
243
+ }
244
+ // We await here so that we fetch jobs in sequence, this is important to avoid unnecessary calls
245
+ // to Redis in high concurrency scenarios.
246
+ const job = await fetchedJob;
247
+ // No more jobs waiting but we have others that could start processing already
248
+ if (!job && numTotal > 1) {
249
+ break;
228
250
  }
229
- // Since there can be undefined jobs in the queue (when a job fails or queue is empty)
230
- // we iterate until we find a job.
231
- let job;
232
- do {
233
- job = await asyncFifoQueue.fetch();
234
- } while (!job && asyncFifoQueue.numQueued() > 0);
235
- if (job) {
236
- const token = job.token;
237
- asyncFifoQueue.add(this.retryIfFailed(() => this.processJob(job, token, () => asyncFifoQueue.numTotal() <= this._concurrency, jobsInProgress), this.opts.runRetryDelay));
251
+ // If there are potential jobs to be processed and blockUntil is set, we should exit to avoid waiting
252
+ // for processing this job.
253
+ if (this.blockUntil) {
254
+ break;
238
255
  }
239
256
  }
240
- this.running = false;
241
- return await asyncFifoQueue.waitAll();
242
- }
243
- catch (error) {
244
- this.running = false;
245
- throw error;
257
+ // Since there can be undefined jobs in the queue (when a job fails or queue is empty)
258
+ // we iterate until we find a job.
259
+ let job;
260
+ do {
261
+ job = await asyncFifoQueue.fetch();
262
+ } while (!job && asyncFifoQueue.numQueued() > 0);
263
+ if (job) {
264
+ const token = job.token;
265
+ asyncFifoQueue.add(this.retryIfFailed(() => this.processJob(job, token, () => asyncFifoQueue.numTotal() <= this._concurrency, jobsInProgress), this.opts.runRetryDelay));
266
+ }
267
+ else if (asyncFifoQueue.numQueued() === 0) {
268
+ await this.waitForRateLimit();
269
+ }
246
270
  }
271
+ return asyncFifoQueue.waitAll();
247
272
  }
248
273
  /**
249
274
  * Returns a promise that resolves to the next job in queue.
@@ -265,14 +290,8 @@ export class Worker extends QueueBase {
265
290
  }, (_b = (_a = nextJob === null || nextJob === void 0 ? void 0 : nextJob.opts) === null || _a === void 0 ? void 0 : _a.telemetry) === null || _b === void 0 ? void 0 : _b.metadata);
266
291
  }
267
292
  async _getNextJob(client, bclient, token, { block = true } = {}) {
268
- var _a;
269
293
  if (this.paused) {
270
- if (block) {
271
- await this.paused;
272
- }
273
- else {
274
- return;
275
- }
294
+ return;
276
295
  }
277
296
  if (this.closing) {
278
297
  return;
@@ -297,13 +316,9 @@ export class Worker extends QueueBase {
297
316
  }
298
317
  }
299
318
  else {
300
- const limitUntil = this.limitUntil;
301
- if (limitUntil) {
302
- (_a = this.abortDelayController) === null || _a === void 0 ? void 0 : _a.abort();
303
- this.abortDelayController = new AbortController();
304
- await this.delay(this.getLimitUntil(limitUntil), this.abortDelayController);
319
+ if (!this.isRateLimited()) {
320
+ return this.moveToActive(client, token, this.opts.name);
305
321
  }
306
- return this.moveToActive(client, token, this.opts.name);
307
322
  }
308
323
  }
309
324
  /**
@@ -328,9 +343,12 @@ export class Worker extends QueueBase {
328
343
  0.001
329
344
  : 0.002;
330
345
  }
346
+ isRateLimited() {
347
+ return this.limitUntil > Date.now();
348
+ }
331
349
  async moveToActive(client, token, name) {
332
- const [jobData, id, limitUntil, delayUntil] = await this.scripts.moveToActive(client, token, name);
333
- this.updateDelays(limitUntil, delayUntil);
350
+ const [jobData, id, rateLimitDelay, delayUntil] = await this.scripts.moveToActive(client, token, name);
351
+ this.updateDelays(rateLimitDelay, delayUntil);
334
352
  return this.nextJobFromJobData(jobData, id, token);
335
353
  }
336
354
  async waitForJob(bclient, blockUntil) {
@@ -339,7 +357,7 @@ export class Worker extends QueueBase {
339
357
  }
340
358
  let timeout;
341
359
  try {
342
- if (!this.closing && !this.limitUntil) {
360
+ if (!this.closing && !this.isRateLimited()) {
343
361
  let blockTimeout = this.getBlockTimeout(blockUntil);
344
362
  if (blockTimeout > 0) {
345
363
  blockTimeout = this.blockingConnection.capabilities.canDoubleTimeout
@@ -358,7 +376,13 @@ export class Worker extends QueueBase {
358
376
  if (result) {
359
377
  const [_key, member, score] = result;
360
378
  if (member) {
361
- return parseInt(score);
379
+ const newBlockUntil = parseInt(score);
380
+ // Use by pro version as rate limited groups could generate lower blockUntil values
381
+ // markers only return delays for delayed jobs
382
+ if (blockUntil && newBlockUntil > blockUntil) {
383
+ return blockUntil;
384
+ }
385
+ return newBlockUntil;
362
386
  }
363
387
  }
364
388
  }
@@ -401,10 +425,10 @@ export class Worker extends QueueBase {
401
425
  return Math.max(opts.drainDelay, this.minimumBlockTimeout);
402
426
  }
403
427
  }
404
- getLimitUntil(limitUntil) {
428
+ getRateLimitDelay(delay) {
405
429
  // We restrict the maximum limit until to 30 second to
406
430
  // be able to promote delayed jobs while queue is rate limited
407
- return Math.min(limitUntil, maximumLimitUntil);
431
+ return Math.min(delay, maximumRateLimitDelay);
408
432
  }
409
433
  /**
410
434
  *
@@ -413,8 +437,14 @@ export class Worker extends QueueBase {
413
437
  async delay(milliseconds, abortController) {
414
438
  await delay(milliseconds || DELAY_TIME_1, abortController);
415
439
  }
416
- updateDelays(limitUntil = 0, delayUntil = 0) {
417
- this.limitUntil = Math.max(limitUntil, 0) || 0;
440
+ updateDelays(limitDelay = 0, delayUntil = 0) {
441
+ const clampedLimit = Math.max(limitDelay, 0);
442
+ if (clampedLimit > 0) {
443
+ this.limitUntil = Date.now() + clampedLimit;
444
+ }
445
+ else {
446
+ this.limitUntil = 0;
447
+ }
418
448
  this.blockUntil = Math.max(delayUntil, 0) || 0;
419
449
  }
420
450
  async nextJobFromJobData(jobData, jobId, token) {
@@ -447,9 +477,6 @@ export class Worker extends QueueBase {
447
477
  }
448
478
  async processJob(job, token, fetchNextCallback = () => true, jobsInProgress) {
449
479
  var _a, _b;
450
- if (!job || this.closing || this.paused) {
451
- return;
452
- }
453
480
  const srcPropagationMedatada = (_b = (_a = job.opts) === null || _a === void 0 ? void 0 : _a.telemetry) === null || _b === void 0 ? void 0 : _b.metadata;
454
481
  return this.trace(SpanKind.CONSUMER, 'process', this.name, async (span) => {
455
482
  span === null || span === void 0 ? void 0 : span.setAttributes({
@@ -457,64 +484,20 @@ export class Worker extends QueueBase {
457
484
  [TelemetryAttributes.WorkerName]: this.opts.name,
458
485
  [TelemetryAttributes.JobId]: job.id,
459
486
  });
460
- const handleCompleted = async (result) => {
461
- jobsInProgress.delete(inProgressItem);
462
- if (!this.connection.closing) {
463
- const completed = await job.moveToCompleted(result, token, fetchNextCallback() && !(this.closing || this.paused));
464
- this.emit('completed', job, result, 'active');
465
- span === null || span === void 0 ? void 0 : span.addEvent('job completed', {
466
- [TelemetryAttributes.JobResult]: JSON.stringify(result),
467
- });
468
- const [jobData, jobId, limitUntil, delayUntil] = completed || [];
469
- this.updateDelays(limitUntil, delayUntil);
470
- return this.nextJobFromJobData(jobData, jobId, token);
471
- }
472
- };
473
- const handleFailed = async (err) => {
474
- jobsInProgress.delete(inProgressItem);
475
- if (!this.connection.closing) {
476
- try {
477
- // Check if the job was manually rate-limited
478
- if (err.message == RATE_LIMIT_ERROR) {
479
- this.limitUntil = await this.moveLimitedBackToWait(job, token);
480
- return;
481
- }
482
- if (err instanceof DelayedError ||
483
- err.name == 'DelayedError' ||
484
- err instanceof WaitingChildrenError ||
485
- err.name == 'WaitingChildrenError') {
486
- return;
487
- }
488
- const result = await job.moveToFailed(err, token, true);
489
- this.emit('failed', job, err, 'active');
490
- span === null || span === void 0 ? void 0 : span.addEvent('job failed', {
491
- [TelemetryAttributes.JobFailedReason]: err.message,
492
- });
493
- if (result) {
494
- const [jobData, jobId, limitUntil, delayUntil] = result;
495
- this.updateDelays(limitUntil, delayUntil);
496
- return this.nextJobFromJobData(jobData, jobId, token);
497
- }
498
- }
499
- catch (err) {
500
- this.emit('error', err);
501
- // It probably means that the job has lost the lock before completion
502
- // A worker will (or already has) moved the job back
503
- // to the waiting list (as stalled)
504
- span === null || span === void 0 ? void 0 : span.recordException(err.message);
505
- }
506
- }
507
- };
508
487
  this.emit('active', job, 'waiting');
509
488
  const processedOn = Date.now();
510
489
  const inProgressItem = { job, ts: processedOn };
511
490
  try {
491
+ if (job.deferredFailure) {
492
+ const failed = await this.handleFailed(new UnrecoverableError(job.deferredFailure), job, token, fetchNextCallback, jobsInProgress, inProgressItem, span);
493
+ return failed;
494
+ }
512
495
  jobsInProgress.add(inProgressItem);
513
496
  const result = await this.callProcessJob(job, token);
514
- return await handleCompleted(result);
497
+ return await this.handleCompleted(result, job, token, fetchNextCallback, jobsInProgress, inProgressItem, span);
515
498
  }
516
499
  catch (err) {
517
- const failed = await handleFailed(err);
500
+ const failed = await this.handleFailed(err, job, token, fetchNextCallback, jobsInProgress, inProgressItem, span);
518
501
  return failed;
519
502
  }
520
503
  finally {
@@ -525,26 +508,73 @@ export class Worker extends QueueBase {
525
508
  }
526
509
  }, srcPropagationMedatada);
527
510
  }
511
+ async handleCompleted(result, job, token, fetchNextCallback = () => true, jobsInProgress, inProgressItem, span) {
512
+ jobsInProgress.delete(inProgressItem);
513
+ if (!this.connection.closing) {
514
+ const completed = await job.moveToCompleted(result, token, fetchNextCallback() && !(this.closing || this.paused));
515
+ this.emit('completed', job, result, 'active');
516
+ span === null || span === void 0 ? void 0 : span.addEvent('job completed', {
517
+ [TelemetryAttributes.JobResult]: JSON.stringify(result),
518
+ });
519
+ const [jobData, jobId, rateLimitDelay, delayUntil] = completed || [];
520
+ this.updateDelays(rateLimitDelay, delayUntil);
521
+ return this.nextJobFromJobData(jobData, jobId, token);
522
+ }
523
+ }
524
+ async handleFailed(err, job, token, fetchNextCallback = () => true, jobsInProgress, inProgressItem, span) {
525
+ jobsInProgress.delete(inProgressItem);
526
+ if (!this.connection.closing) {
527
+ try {
528
+ // Check if the job was manually rate-limited
529
+ if (err.message == RATE_LIMIT_ERROR) {
530
+ const rateLimitTtl = await this.moveLimitedBackToWait(job, token);
531
+ this.limitUntil = rateLimitTtl > 0 ? Date.now() + rateLimitTtl : 0;
532
+ return;
533
+ }
534
+ if (err instanceof DelayedError ||
535
+ err.name == 'DelayedError' ||
536
+ err instanceof WaitingError ||
537
+ err.name == 'WaitingError' ||
538
+ err instanceof WaitingChildrenError ||
539
+ err.name == 'WaitingChildrenError') {
540
+ return;
541
+ }
542
+ const result = await job.moveToFailed(err, token, fetchNextCallback() && !(this.closing || this.paused));
543
+ this.emit('failed', job, err, 'active');
544
+ span === null || span === void 0 ? void 0 : span.addEvent('job failed', {
545
+ [TelemetryAttributes.JobFailedReason]: err.message,
546
+ });
547
+ if (result) {
548
+ const [jobData, jobId, rateLimitDelay, delayUntil] = result;
549
+ this.updateDelays(rateLimitDelay, delayUntil);
550
+ return this.nextJobFromJobData(jobData, jobId, token);
551
+ }
552
+ }
553
+ catch (err) {
554
+ this.emit('error', err);
555
+ // It probably means that the job has lost the lock before completion
556
+ // A worker will (or already has) moved the job back
557
+ // to the waiting list (as stalled)
558
+ span === null || span === void 0 ? void 0 : span.recordException(err.message);
559
+ }
560
+ }
561
+ }
528
562
  /**
529
563
  *
530
564
  * Pauses the processing of this queue only for this worker.
531
565
  */
532
566
  async pause(doNotWaitActive) {
533
567
  await this.trace(SpanKind.INTERNAL, 'pause', this.name, async (span) => {
568
+ var _a;
534
569
  span === null || span === void 0 ? void 0 : span.setAttributes({
535
570
  [TelemetryAttributes.WorkerId]: this.id,
536
571
  [TelemetryAttributes.WorkerName]: this.opts.name,
537
572
  [TelemetryAttributes.WorkerDoNotWaitActive]: doNotWaitActive,
538
573
  });
539
574
  if (!this.paused) {
540
- this.paused = new Promise(resolve => {
541
- this.resumeWorker = function () {
542
- resolve();
543
- this.paused = null; // Allow pause to be checked externally for paused state.
544
- this.resumeWorker = null;
545
- };
546
- });
575
+ this.paused = true;
547
576
  await (!doNotWaitActive && this.whenCurrentJobsFinished());
577
+ (_a = this.stalledCheckStopper) === null || _a === void 0 ? void 0 : _a.call(this);
548
578
  this.emit('paused');
549
579
  }
550
580
  });
@@ -554,13 +584,16 @@ export class Worker extends QueueBase {
554
584
  * Resumes processing of this worker (if paused).
555
585
  */
556
586
  resume() {
557
- if (this.resumeWorker) {
587
+ if (!this.running) {
558
588
  this.trace(SpanKind.INTERNAL, 'resume', this.name, span => {
559
589
  span === null || span === void 0 ? void 0 : span.setAttributes({
560
590
  [TelemetryAttributes.WorkerId]: this.id,
561
591
  [TelemetryAttributes.WorkerName]: this.opts.name,
562
592
  });
563
- this.resumeWorker();
593
+ this.paused = false;
594
+ if (this.processFn) {
595
+ this.run();
596
+ }
564
597
  this.emit('resumed');
565
598
  });
566
599
  }
@@ -599,17 +632,16 @@ export class Worker extends QueueBase {
599
632
  if (this.closing) {
600
633
  return this.closing;
601
634
  }
602
- await this.trace(SpanKind.INTERNAL, 'close', this.name, async (span) => {
603
- span === null || span === void 0 ? void 0 : span.setAttributes({
604
- [TelemetryAttributes.WorkerId]: this.id,
605
- [TelemetryAttributes.WorkerName]: this.opts.name,
606
- [TelemetryAttributes.WorkerForceClose]: force,
607
- });
608
- this.closing = (async () => {
635
+ this.closing = (async () => {
636
+ await this.trace(SpanKind.INTERNAL, 'close', this.name, async (span) => {
609
637
  var _a, _b;
638
+ span === null || span === void 0 ? void 0 : span.setAttributes({
639
+ [TelemetryAttributes.WorkerId]: this.id,
640
+ [TelemetryAttributes.WorkerName]: this.opts.name,
641
+ [TelemetryAttributes.WorkerForceClose]: force,
642
+ });
610
643
  this.emit('closing', 'closing queue');
611
644
  (_a = this.abortDelayController) === null || _a === void 0 ? void 0 : _a.abort();
612
- this.resume();
613
645
  // Define the async cleanup functions
614
646
  const asyncCleanups = [
615
647
  () => {
@@ -632,9 +664,9 @@ export class Worker extends QueueBase {
632
664
  (_b = this.stalledCheckStopper) === null || _b === void 0 ? void 0 : _b.call(this);
633
665
  this.closed = true;
634
666
  this.emit('closed');
635
- })();
636
- return await this.closing;
637
- });
667
+ });
668
+ })();
669
+ return await this.closing;
638
670
  }
639
671
  /**
640
672
  *
@@ -664,7 +696,7 @@ export class Worker extends QueueBase {
664
696
  }
665
697
  }
666
698
  async stalledChecker() {
667
- while (!this.closing) {
699
+ while (!(this.closing || this.paused)) {
668
700
  try {
669
701
  await this.checkConnectionError(() => this.moveStalledJobsToWait());
670
702
  }
@@ -728,8 +760,8 @@ export class Worker extends QueueBase {
728
760
  else {
729
761
  reconnect = false;
730
762
  }
731
- if (this.asyncFifoQueue) {
732
- await this.asyncFifoQueue.waitAll();
763
+ if (this.mainLoopRunning) {
764
+ await this.mainLoopRunning;
733
765
  }
734
766
  reconnect && (await this.blockingConnection.reconnect());
735
767
  }
@@ -771,13 +803,11 @@ export class Worker extends QueueBase {
771
803
  }
772
804
  async moveStalledJobsToWait() {
773
805
  await this.trace(SpanKind.INTERNAL, 'moveStalledJobsToWait', this.name, async (span) => {
774
- const chunkSize = 50;
775
- const [failed, stalled] = await this.scripts.moveStalledJobsToWait();
806
+ const stalled = await this.scripts.moveStalledJobsToWait();
776
807
  span === null || span === void 0 ? void 0 : span.setAttributes({
777
808
  [TelemetryAttributes.WorkerId]: this.id,
778
809
  [TelemetryAttributes.WorkerName]: this.opts.name,
779
810
  [TelemetryAttributes.WorkerStalledJobs]: stalled,
780
- [TelemetryAttributes.WorkerFailedJobs]: failed,
781
811
  });
782
812
  stalled.forEach((jobId) => {
783
813
  span === null || span === void 0 ? void 0 : span.addEvent('job stalled', {
@@ -785,31 +815,10 @@ export class Worker extends QueueBase {
785
815
  });
786
816
  this.emit('stalled', jobId, 'active');
787
817
  });
788
- // Todo: check if there any listeners on failed event
789
- const jobPromises = [];
790
- for (let i = 0; i < failed.length; i++) {
791
- jobPromises.push(Job.fromId(this, failed[i]));
792
- if ((i + 1) % chunkSize === 0) {
793
- this.notifyFailedJobs(await Promise.all(jobPromises));
794
- jobPromises.length = 0;
795
- }
796
- }
797
- this.notifyFailedJobs(await Promise.all(jobPromises));
798
- });
799
- }
800
- notifyFailedJobs(failedJobs, span) {
801
- const failedReason = 'job stalled more than allowable limit';
802
- failedJobs.forEach((job) => {
803
- span === null || span === void 0 ? void 0 : span.addEvent('job failed', {
804
- [TelemetryAttributes.JobId]: job.id,
805
- [TelemetryAttributes.JobName]: job.name,
806
- [TelemetryAttributes.JobFailedReason]: failedReason,
807
- });
808
- this.emit('failed', job, new Error(failedReason), 'active');
809
818
  });
810
819
  }
811
820
  moveLimitedBackToWait(job, token) {
812
- return this.scripts.moveJobFromActiveToWait(job.id, token);
821
+ return job.moveToWait(token);
813
822
  }
814
823
  }
815
824
  //# sourceMappingURL=worker.js.map
@@ -26,7 +26,7 @@
26
26
  [8] parent? {id, queueKey}
27
27
  [9] repeat job key
28
28
  [10] deduplication key
29
-
29
+
30
30
  ARGV[2] Json stringified job data
31
31
  ARGV[3] msgpacked options
32
32
 
@@ -56,9 +56,8 @@ local deduplicationKey = args[10]
56
56
  local parentData
57
57
 
58
58
  -- Includes
59
- --- @include "includes/addDelayMarkerIfNeeded"
59
+ --- @include "includes/addDelayedJob"
60
60
  --- @include "includes/deduplicateJob"
61
- --- @include "includes/getDelayedScore"
62
61
  --- @include "includes/getOrSetMaxEvents"
63
62
  --- @include "includes/handleDuplicatedJob"
64
63
  --- @include "includes/storeJob"
@@ -90,26 +89,16 @@ else
90
89
  end
91
90
  end
92
91
 
93
- local deduplicationJobId = deduplicateJob(args[1], opts['de'],
94
- jobId, deduplicationKey, eventsKey, maxEvents)
92
+ local deduplicationJobId = deduplicateJob(opts['de'], jobId, delayedKey, deduplicationKey,
93
+ eventsKey, maxEvents, args[1])
95
94
  if deduplicationJobId then
96
95
  return deduplicationJobId
97
96
  end
98
97
 
99
- -- Store the job.
100
98
  local delay, priority = storeJob(eventsKey, jobIdKey, jobId, args[3], ARGV[2],
101
- opts, timestamp, parentKey, parentData,
102
- repeatJobKey)
103
-
104
- local score, delayedTimestamp = getDelayedScore(delayedKey, timestamp, tonumber(delay))
105
-
106
- rcall("ZADD", delayedKey, score, jobId)
107
- rcall("XADD", eventsKey, "MAXLEN", "~", maxEvents, "*", "event", "delayed",
108
- "jobId", jobId, "delay", delayedTimestamp)
99
+ opts, timestamp, parentKey, parentData, repeatJobKey)
109
100
 
110
- -- mark that a delayed job is available
111
- local markerKey = KEYS[1]
112
- addDelayMarkerIfNeeded(markerKey, delayedKey)
101
+ addDelayedJob(jobId, delayedKey, eventsKey, timestamp, maxEvents, KEYS[1], delay)
113
102
 
114
103
  -- Check if this job is a child of another job, if so add it to the parents dependencies
115
104
  if parentDependenciesKey ~= nil then