bullmq 5.81.3 → 6.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (390) hide show
  1. package/dist/cjs/classes/finished-errors.js +55 -0
  2. package/dist/cjs/classes/flow-producer.js +106 -109
  3. package/dist/cjs/classes/index.js +1 -2
  4. package/dist/cjs/classes/job-scheduler.js +120 -43
  5. package/dist/cjs/classes/job.js +136 -305
  6. package/dist/cjs/classes/queue-base.js +35 -41
  7. package/dist/cjs/classes/queue-events-producer.js +4 -9
  8. package/dist/cjs/classes/queue-events.js +10 -21
  9. package/dist/cjs/classes/queue-getters.js +47 -72
  10. package/dist/cjs/classes/queue.js +57 -215
  11. package/dist/cjs/classes/redis-connection.js +11 -1
  12. package/dist/cjs/classes/{scripts.js → redis-queue-backend.js} +838 -195
  13. package/dist/cjs/classes/worker.js +95 -144
  14. package/dist/cjs/commands/addJobScheduler-11.lua +0 -4
  15. package/dist/cjs/commands/addStandardJob-9.lua +7 -5
  16. package/dist/cjs/commands/changePriority-7.lua +10 -7
  17. package/dist/cjs/commands/getCountsPerPriority-4.lua +1 -8
  18. package/dist/cjs/commands/includes/deduplicateJob.lua +5 -8
  19. package/dist/cjs/commands/includes/deduplicateJobWithoutReplace.lua +13 -18
  20. package/dist/cjs/commands/includes/fetchNextJob.lua +4 -4
  21. package/dist/cjs/commands/includes/getQueueMetadata.lua +21 -0
  22. package/dist/cjs/commands/includes/getWaitPlusPrioritizedCount.lua +10 -0
  23. package/dist/cjs/commands/includes/moveJobToWait.lua +3 -3
  24. package/dist/cjs/commands/includes/moveParentToWait.lua +4 -5
  25. package/dist/cjs/commands/includes/removeParentDependencyKey.lua +4 -4
  26. package/dist/cjs/commands/includes/storeAndEnqueueJob.lua +3 -3
  27. package/dist/cjs/commands/includes/storeDeduplicatedNextJob.lua +4 -7
  28. package/dist/cjs/commands/moveJobFromActiveToWait-9.lua +3 -3
  29. package/dist/cjs/commands/moveJobsToWait-8.lua +3 -3
  30. package/dist/cjs/commands/moveStalledJobsToWait-9.lua +0 -1
  31. package/dist/cjs/commands/moveToActive-11.lua +4 -4
  32. package/dist/cjs/commands/obliterate-2.lua +7 -0
  33. package/dist/cjs/commands/pause-7.lua +27 -5
  34. package/dist/cjs/commands/promote-9.lua +5 -5
  35. package/dist/cjs/commands/reprocessJob-8.lua +3 -3
  36. package/dist/cjs/commands/retryJob-11.lua +3 -4
  37. package/dist/cjs/commands/updateJobScheduler-12.lua +1 -13
  38. package/dist/cjs/enums/telemetry-attributes.js +1 -8
  39. package/dist/cjs/index.js +3 -1
  40. package/dist/cjs/interfaces/index.js +1 -1
  41. package/dist/cjs/postgres/commands/add_flow.sql +3 -0
  42. package/dist/cjs/postgres/commands/add_job.sql +5 -0
  43. package/dist/cjs/postgres/commands/add_job_scheduler.sql +6 -0
  44. package/dist/cjs/postgres/commands/add_jobs_bulk.sql +3 -0
  45. package/dist/cjs/postgres/commands/add_log.sql +14 -0
  46. package/dist/cjs/postgres/commands/change_delay.sql +3 -0
  47. package/dist/cjs/postgres/commands/change_priority.sql +3 -0
  48. package/dist/cjs/postgres/commands/clean.sql +3 -0
  49. package/dist/cjs/postgres/commands/clear_logs.sql +9 -0
  50. package/dist/cjs/postgres/commands/collect_metrics.sql +4 -0
  51. package/dist/cjs/postgres/commands/delete_deduplication_key.sql +6 -0
  52. package/dist/cjs/postgres/commands/drain.sql +2 -0
  53. package/dist/cjs/postgres/commands/extend_lock.sql +3 -0
  54. package/dist/cjs/postgres/commands/extend_locks.sql +25 -0
  55. package/dist/cjs/postgres/commands/get_client_list.sql +11 -0
  56. package/dist/cjs/postgres/commands/get_counts.sql +13 -0
  57. package/dist/cjs/postgres/commands/get_counts_per_priority.sql +14 -0
  58. package/dist/cjs/postgres/commands/get_deduplication_job_id.sql +7 -0
  59. package/dist/cjs/postgres/commands/get_dependencies.sql +8 -0
  60. package/dist/cjs/postgres/commands/get_dependencies_page.sql +7 -0
  61. package/dist/cjs/postgres/commands/get_dependency_counts.sql +9 -0
  62. package/dist/cjs/postgres/commands/get_ignored_children_failures.sql +7 -0
  63. package/dist/cjs/postgres/commands/get_job_data.sql +2 -0
  64. package/dist/cjs/postgres/commands/get_job_logs_asc.sql +6 -0
  65. package/dist/cjs/postgres/commands/get_job_logs_count.sql +2 -0
  66. package/dist/cjs/postgres/commands/get_job_logs_desc.sql +6 -0
  67. package/dist/cjs/postgres/commands/get_job_scheduler.sql +6 -0
  68. package/dist/cjs/postgres/commands/get_job_schedulers_count.sql +2 -0
  69. package/dist/cjs/postgres/commands/get_job_schedulers_range.sql +10 -0
  70. package/dist/cjs/postgres/commands/get_metrics.sql +14 -0
  71. package/dist/cjs/postgres/commands/get_processed_children_values.sql +8 -0
  72. package/dist/cjs/postgres/commands/get_queue_meta.sql +2 -0
  73. package/dist/cjs/postgres/commands/get_queue_meta_field.sql +2 -0
  74. package/dist/cjs/postgres/commands/get_queue_meta_fields.sql +3 -0
  75. package/dist/cjs/postgres/commands/get_range.sql +3 -0
  76. package/dist/cjs/postgres/commands/get_rate_limit_ttl.sql +3 -0
  77. package/dist/cjs/postgres/commands/get_state.sql +2 -0
  78. package/dist/cjs/postgres/commands/has_queue_meta_field.sql +4 -0
  79. package/dist/cjs/postgres/commands/has_waiting_job.sql +11 -0
  80. package/dist/cjs/postgres/commands/is_finished.sql +4 -0
  81. package/dist/cjs/postgres/commands/is_job_in_state.sql +6 -0
  82. package/dist/cjs/postgres/commands/is_job_in_wait.sql +15 -0
  83. package/dist/cjs/postgres/commands/is_job_prioritized.sql +6 -0
  84. package/dist/cjs/postgres/commands/is_job_scheduler.sql +4 -0
  85. package/dist/cjs/postgres/commands/is_maxed.sql +10 -0
  86. package/dist/cjs/postgres/commands/listen_events.sql +3 -0
  87. package/dist/cjs/postgres/commands/listen_jobs.sql +4 -0
  88. package/dist/cjs/postgres/commands/move_active_to_wait.sql +4 -0
  89. package/dist/cjs/postgres/commands/move_stalled_jobs_to_wait.sql +4 -0
  90. package/dist/cjs/postgres/commands/move_to_active.sql +4 -0
  91. package/dist/cjs/postgres/commands/move_to_completed.sql +4 -0
  92. package/dist/cjs/postgres/commands/move_to_completed_fetch.sql +9 -0
  93. package/dist/cjs/postgres/commands/move_to_delayed.sql +4 -0
  94. package/dist/cjs/postgres/commands/move_to_failed.sql +4 -0
  95. package/dist/cjs/postgres/commands/move_to_failed_fetch.sql +9 -0
  96. package/dist/cjs/postgres/commands/move_to_waiting_children.sql +3 -0
  97. package/dist/cjs/postgres/commands/next_delay.sql +2 -0
  98. package/dist/cjs/postgres/commands/next_signal.sql +3 -0
  99. package/dist/cjs/postgres/commands/obliterate.sql +4 -0
  100. package/dist/cjs/postgres/commands/paginate_dependencies.sql +19 -0
  101. package/dist/cjs/postgres/commands/pause.sql +2 -0
  102. package/dist/cjs/postgres/commands/promote.sql +3 -0
  103. package/dist/cjs/postgres/commands/promote_jobs.sql +3 -0
  104. package/dist/cjs/postgres/commands/publish_event.sql +3 -0
  105. package/dist/cjs/postgres/commands/read_events.sql +6 -0
  106. package/dist/cjs/postgres/commands/read_events_max.sql +3 -0
  107. package/dist/cjs/postgres/commands/remove.sql +3 -0
  108. package/dist/cjs/postgres/commands/remove_child_dependency.sql +4 -0
  109. package/dist/cjs/postgres/commands/remove_deduplication_key.sql +9 -0
  110. package/dist/cjs/postgres/commands/remove_job_scheduler.sql +3 -0
  111. package/dist/cjs/postgres/commands/remove_queue_meta_fields.sql +2 -0
  112. package/dist/cjs/postgres/commands/remove_rate_limit.sql +6 -0
  113. package/dist/cjs/postgres/commands/remove_unprocessed_children.sql +3 -0
  114. package/dist/cjs/postgres/commands/reprocess_job.sql +4 -0
  115. package/dist/cjs/postgres/commands/retry_job.sql +3 -0
  116. package/dist/cjs/postgres/commands/retry_jobs.sql +3 -0
  117. package/dist/cjs/postgres/commands/set_queue_meta.sql +4 -0
  118. package/dist/cjs/postgres/commands/set_rate_limit.sql +3 -0
  119. package/dist/cjs/postgres/commands/trim_logs.sql +3 -0
  120. package/dist/cjs/postgres/commands/update_data.sql +3 -0
  121. package/dist/cjs/postgres/commands/update_job_scheduler.sql +5 -0
  122. package/dist/cjs/postgres/commands/update_progress.sql +3 -0
  123. package/dist/cjs/postgres/create-postgres-backend.js +46 -0
  124. package/dist/cjs/postgres/index.js +23 -0
  125. package/dist/cjs/postgres/migrations/0001_schema.sql +348 -0
  126. package/dist/cjs/postgres/migrations/0002_functions.sql +3473 -0
  127. package/dist/cjs/postgres/migrations/index.js +26 -0
  128. package/dist/cjs/postgres/migrator.js +229 -0
  129. package/dist/cjs/postgres/pg-types.js +14 -0
  130. package/dist/cjs/postgres/postgres-connection.js +211 -0
  131. package/dist/cjs/postgres/postgres-queue-backend.js +1705 -0
  132. package/dist/cjs/postgres/sql-loader.js +47 -0
  133. package/dist/cjs/scripts/addDelayedJob-6.js +25 -57
  134. package/dist/cjs/scripts/addJobScheduler-11.js +11 -18
  135. package/dist/cjs/scripts/addParentJob-6.js +20 -49
  136. package/dist/cjs/scripts/addPrioritizedJob-9.js +25 -57
  137. package/dist/cjs/scripts/addStandardJob-9.js +31 -61
  138. package/dist/cjs/scripts/changePriority-7.js +15 -16
  139. package/dist/cjs/scripts/cleanJobsInSet-3.js +9 -13
  140. package/dist/cjs/scripts/drain-5.js +9 -13
  141. package/dist/cjs/scripts/getCountsPerPriority-4.js +1 -13
  142. package/dist/cjs/scripts/index.js +0 -3
  143. package/dist/cjs/scripts/moveJobFromActiveToWait-9.js +8 -12
  144. package/dist/cjs/scripts/moveJobsToWait-8.js +8 -12
  145. package/dist/cjs/scripts/moveStalledJobsToWait-9.js +24 -28
  146. package/dist/cjs/scripts/moveToActive-11.js +22 -23
  147. package/dist/cjs/scripts/moveToDelayed-12.js +22 -23
  148. package/dist/cjs/scripts/moveToFinished-14.js +30 -32
  149. package/dist/cjs/scripts/obliterate-2.js +15 -13
  150. package/dist/cjs/scripts/pause-7.js +31 -5
  151. package/dist/cjs/scripts/promote-9.js +10 -14
  152. package/dist/cjs/scripts/removeChildDependency-1.js +9 -13
  153. package/dist/cjs/scripts/removeJob-2.js +9 -13
  154. package/dist/cjs/scripts/removeUnprocessedChildren-2.js +9 -13
  155. package/dist/cjs/scripts/reprocessJob-8.js +8 -12
  156. package/dist/cjs/scripts/retryJob-11.js +3 -23
  157. package/dist/cjs/scripts/updateJobScheduler-12.js +9 -22
  158. package/dist/cjs/tsconfig-cjs.tsbuildinfo +1 -1
  159. package/dist/cjs/utils/create-backend.js +81 -0
  160. package/dist/cjs/utils/index.js +4 -25
  161. package/dist/cjs/version.js +1 -1
  162. package/dist/esm/classes/finished-errors.d.ts +14 -0
  163. package/dist/esm/classes/finished-errors.js +52 -0
  164. package/dist/esm/classes/flow-producer.d.ts +45 -29
  165. package/dist/esm/classes/flow-producer.js +107 -110
  166. package/dist/esm/classes/index.d.ts +1 -2
  167. package/dist/esm/classes/index.js +1 -2
  168. package/dist/esm/classes/job-scheduler.d.ts +13 -4
  169. package/dist/esm/classes/job-scheduler.js +117 -43
  170. package/dist/esm/classes/job.d.ts +25 -60
  171. package/dist/esm/classes/job.js +137 -306
  172. package/dist/esm/classes/queue-base.d.ts +19 -20
  173. package/dist/esm/classes/queue-base.js +36 -42
  174. package/dist/esm/classes/queue-events-producer.d.ts +2 -3
  175. package/dist/esm/classes/queue-events-producer.js +4 -9
  176. package/dist/esm/classes/queue-events.d.ts +2 -19
  177. package/dist/esm/classes/queue-events.js +11 -22
  178. package/dist/esm/classes/queue-getters.d.ts +4 -5
  179. package/dist/esm/classes/queue-getters.js +48 -73
  180. package/dist/esm/classes/queue.d.ts +19 -60
  181. package/dist/esm/classes/queue.js +57 -215
  182. package/dist/esm/classes/redis-connection.js +11 -1
  183. package/dist/esm/classes/{scripts.d.ts → redis-queue-backend.d.ts} +227 -52
  184. package/dist/esm/classes/{scripts.js → redis-queue-backend.js} +837 -194
  185. package/dist/esm/classes/worker.d.ts +15 -15
  186. package/dist/esm/classes/worker.js +97 -146
  187. package/dist/esm/commands/addJobScheduler-11.lua +0 -4
  188. package/dist/esm/commands/addStandardJob-9.lua +7 -5
  189. package/dist/esm/commands/changePriority-7.lua +10 -7
  190. package/dist/esm/commands/getCountsPerPriority-4.lua +1 -8
  191. package/dist/esm/commands/includes/deduplicateJob.lua +5 -8
  192. package/dist/esm/commands/includes/deduplicateJobWithoutReplace.lua +13 -18
  193. package/dist/esm/commands/includes/fetchNextJob.lua +4 -4
  194. package/dist/esm/commands/includes/getQueueMetadata.lua +21 -0
  195. package/dist/esm/commands/includes/getWaitPlusPrioritizedCount.lua +10 -0
  196. package/dist/esm/commands/includes/moveJobToWait.lua +3 -3
  197. package/dist/esm/commands/includes/moveParentToWait.lua +4 -5
  198. package/dist/esm/commands/includes/removeParentDependencyKey.lua +4 -4
  199. package/dist/esm/commands/includes/storeAndEnqueueJob.lua +3 -3
  200. package/dist/esm/commands/includes/storeDeduplicatedNextJob.lua +4 -7
  201. package/dist/esm/commands/moveJobFromActiveToWait-9.lua +3 -3
  202. package/dist/esm/commands/moveJobsToWait-8.lua +3 -3
  203. package/dist/esm/commands/moveStalledJobsToWait-9.lua +0 -1
  204. package/dist/esm/commands/moveToActive-11.lua +4 -4
  205. package/dist/esm/commands/obliterate-2.lua +7 -0
  206. package/dist/esm/commands/pause-7.lua +27 -5
  207. package/dist/esm/commands/promote-9.lua +5 -5
  208. package/dist/esm/commands/reprocessJob-8.lua +3 -3
  209. package/dist/esm/commands/retryJob-11.lua +3 -4
  210. package/dist/esm/commands/updateJobScheduler-12.lua +1 -13
  211. package/dist/esm/enums/telemetry-attributes.d.ts +1 -8
  212. package/dist/esm/enums/telemetry-attributes.js +1 -8
  213. package/dist/esm/index.d.ts +2 -1
  214. package/dist/esm/index.js +3 -1
  215. package/dist/esm/interfaces/base-job-options.d.ts +0 -5
  216. package/dist/esm/interfaces/flow-job.d.ts +20 -7
  217. package/dist/esm/interfaces/index.d.ts +1 -1
  218. package/dist/esm/interfaces/index.js +1 -1
  219. package/dist/esm/interfaces/job-json.d.ts +6 -30
  220. package/dist/esm/interfaces/minimal-job.d.ts +2 -2
  221. package/dist/esm/interfaces/minimal-queue.d.ts +16 -11
  222. package/dist/esm/interfaces/queue-backend.d.ts +538 -0
  223. package/dist/esm/interfaces/queue-options.d.ts +26 -8
  224. package/dist/esm/interfaces/repeat-options.d.ts +14 -2
  225. package/dist/esm/interfaces/script-queue-context.d.ts +6 -0
  226. package/dist/esm/interfaces/telemetry.d.ts +1 -1
  227. package/dist/esm/interfaces/worker-options.d.ts +2 -2
  228. package/dist/esm/postgres/commands/add_flow.sql +3 -0
  229. package/dist/esm/postgres/commands/add_job.sql +5 -0
  230. package/dist/esm/postgres/commands/add_job_scheduler.sql +6 -0
  231. package/dist/esm/postgres/commands/add_jobs_bulk.sql +3 -0
  232. package/dist/esm/postgres/commands/add_log.sql +14 -0
  233. package/dist/esm/postgres/commands/change_delay.sql +3 -0
  234. package/dist/esm/postgres/commands/change_priority.sql +3 -0
  235. package/dist/esm/postgres/commands/clean.sql +3 -0
  236. package/dist/esm/postgres/commands/clear_logs.sql +9 -0
  237. package/dist/esm/postgres/commands/collect_metrics.sql +4 -0
  238. package/dist/esm/postgres/commands/delete_deduplication_key.sql +6 -0
  239. package/dist/esm/postgres/commands/drain.sql +2 -0
  240. package/dist/esm/postgres/commands/extend_lock.sql +3 -0
  241. package/dist/esm/postgres/commands/extend_locks.sql +25 -0
  242. package/dist/esm/postgres/commands/get_client_list.sql +11 -0
  243. package/dist/esm/postgres/commands/get_counts.sql +13 -0
  244. package/dist/esm/postgres/commands/get_counts_per_priority.sql +14 -0
  245. package/dist/esm/postgres/commands/get_deduplication_job_id.sql +7 -0
  246. package/dist/esm/postgres/commands/get_dependencies.sql +8 -0
  247. package/dist/esm/postgres/commands/get_dependencies_page.sql +7 -0
  248. package/dist/esm/postgres/commands/get_dependency_counts.sql +9 -0
  249. package/dist/esm/postgres/commands/get_ignored_children_failures.sql +7 -0
  250. package/dist/esm/postgres/commands/get_job_data.sql +2 -0
  251. package/dist/esm/postgres/commands/get_job_logs_asc.sql +6 -0
  252. package/dist/esm/postgres/commands/get_job_logs_count.sql +2 -0
  253. package/dist/esm/postgres/commands/get_job_logs_desc.sql +6 -0
  254. package/dist/esm/postgres/commands/get_job_scheduler.sql +6 -0
  255. package/dist/esm/postgres/commands/get_job_schedulers_count.sql +2 -0
  256. package/dist/esm/postgres/commands/get_job_schedulers_range.sql +10 -0
  257. package/dist/esm/postgres/commands/get_metrics.sql +14 -0
  258. package/dist/esm/postgres/commands/get_processed_children_values.sql +8 -0
  259. package/dist/esm/postgres/commands/get_queue_meta.sql +2 -0
  260. package/dist/esm/postgres/commands/get_queue_meta_field.sql +2 -0
  261. package/dist/esm/postgres/commands/get_queue_meta_fields.sql +3 -0
  262. package/dist/esm/postgres/commands/get_range.sql +3 -0
  263. package/dist/esm/postgres/commands/get_rate_limit_ttl.sql +3 -0
  264. package/dist/esm/postgres/commands/get_state.sql +2 -0
  265. package/dist/esm/postgres/commands/has_queue_meta_field.sql +4 -0
  266. package/dist/esm/postgres/commands/has_waiting_job.sql +11 -0
  267. package/dist/esm/postgres/commands/is_finished.sql +4 -0
  268. package/dist/esm/postgres/commands/is_job_in_state.sql +6 -0
  269. package/dist/esm/postgres/commands/is_job_in_wait.sql +15 -0
  270. package/dist/esm/postgres/commands/is_job_prioritized.sql +6 -0
  271. package/dist/esm/postgres/commands/is_job_scheduler.sql +4 -0
  272. package/dist/esm/postgres/commands/is_maxed.sql +10 -0
  273. package/dist/esm/postgres/commands/listen_events.sql +3 -0
  274. package/dist/esm/postgres/commands/listen_jobs.sql +4 -0
  275. package/dist/esm/postgres/commands/move_active_to_wait.sql +4 -0
  276. package/dist/esm/postgres/commands/move_stalled_jobs_to_wait.sql +4 -0
  277. package/dist/esm/postgres/commands/move_to_active.sql +4 -0
  278. package/dist/esm/postgres/commands/move_to_completed.sql +4 -0
  279. package/dist/esm/postgres/commands/move_to_completed_fetch.sql +9 -0
  280. package/dist/esm/postgres/commands/move_to_delayed.sql +4 -0
  281. package/dist/esm/postgres/commands/move_to_failed.sql +4 -0
  282. package/dist/esm/postgres/commands/move_to_failed_fetch.sql +9 -0
  283. package/dist/esm/postgres/commands/move_to_waiting_children.sql +3 -0
  284. package/dist/esm/postgres/commands/next_delay.sql +2 -0
  285. package/dist/esm/postgres/commands/next_signal.sql +3 -0
  286. package/dist/esm/postgres/commands/obliterate.sql +4 -0
  287. package/dist/esm/postgres/commands/paginate_dependencies.sql +19 -0
  288. package/dist/esm/postgres/commands/pause.sql +2 -0
  289. package/dist/esm/postgres/commands/promote.sql +3 -0
  290. package/dist/esm/postgres/commands/promote_jobs.sql +3 -0
  291. package/dist/esm/postgres/commands/publish_event.sql +3 -0
  292. package/dist/esm/postgres/commands/read_events.sql +6 -0
  293. package/dist/esm/postgres/commands/read_events_max.sql +3 -0
  294. package/dist/esm/postgres/commands/remove.sql +3 -0
  295. package/dist/esm/postgres/commands/remove_child_dependency.sql +4 -0
  296. package/dist/esm/postgres/commands/remove_deduplication_key.sql +9 -0
  297. package/dist/esm/postgres/commands/remove_job_scheduler.sql +3 -0
  298. package/dist/esm/postgres/commands/remove_queue_meta_fields.sql +2 -0
  299. package/dist/esm/postgres/commands/remove_rate_limit.sql +6 -0
  300. package/dist/esm/postgres/commands/remove_unprocessed_children.sql +3 -0
  301. package/dist/esm/postgres/commands/reprocess_job.sql +4 -0
  302. package/dist/esm/postgres/commands/retry_job.sql +3 -0
  303. package/dist/esm/postgres/commands/retry_jobs.sql +3 -0
  304. package/dist/esm/postgres/commands/set_queue_meta.sql +4 -0
  305. package/dist/esm/postgres/commands/set_rate_limit.sql +3 -0
  306. package/dist/esm/postgres/commands/trim_logs.sql +3 -0
  307. package/dist/esm/postgres/commands/update_data.sql +3 -0
  308. package/dist/esm/postgres/commands/update_job_scheduler.sql +5 -0
  309. package/dist/esm/postgres/commands/update_progress.sql +3 -0
  310. package/dist/esm/postgres/create-postgres-backend.d.ts +20 -0
  311. package/dist/esm/postgres/create-postgres-backend.js +42 -0
  312. package/dist/esm/postgres/index.d.ts +6 -0
  313. package/dist/esm/postgres/index.js +6 -0
  314. package/dist/esm/postgres/migrations/0001_schema.sql +348 -0
  315. package/dist/esm/postgres/migrations/0002_functions.sql +3473 -0
  316. package/dist/esm/postgres/migrations/index.d.ts +24 -0
  317. package/dist/esm/postgres/migrations/index.js +23 -0
  318. package/dist/esm/postgres/migrator.d.ts +128 -0
  319. package/dist/esm/postgres/migrator.js +220 -0
  320. package/dist/esm/postgres/pg-types.d.ts +98 -0
  321. package/dist/esm/postgres/pg-types.js +11 -0
  322. package/dist/esm/postgres/postgres-connection.d.ts +133 -0
  323. package/dist/esm/postgres/postgres-connection.js +207 -0
  324. package/dist/esm/postgres/postgres-queue-backend.d.ts +304 -0
  325. package/dist/esm/postgres/postgres-queue-backend.js +1701 -0
  326. package/dist/esm/postgres/sql-loader.d.ts +6 -0
  327. package/dist/esm/postgres/sql-loader.js +43 -0
  328. package/dist/esm/scripts/addDelayedJob-6.js +25 -57
  329. package/dist/esm/scripts/addJobScheduler-11.js +11 -18
  330. package/dist/esm/scripts/addParentJob-6.js +20 -49
  331. package/dist/esm/scripts/addPrioritizedJob-9.js +25 -57
  332. package/dist/esm/scripts/addStandardJob-9.js +31 -61
  333. package/dist/esm/scripts/changePriority-7.js +15 -16
  334. package/dist/esm/scripts/cleanJobsInSet-3.js +9 -13
  335. package/dist/esm/scripts/drain-5.js +9 -13
  336. package/dist/esm/scripts/getCountsPerPriority-4.js +1 -13
  337. package/dist/esm/scripts/index.d.ts +0 -3
  338. package/dist/esm/scripts/index.js +0 -3
  339. package/dist/esm/scripts/moveJobFromActiveToWait-9.js +8 -12
  340. package/dist/esm/scripts/moveJobsToWait-8.js +8 -12
  341. package/dist/esm/scripts/moveStalledJobsToWait-9.js +24 -28
  342. package/dist/esm/scripts/moveToActive-11.js +22 -23
  343. package/dist/esm/scripts/moveToDelayed-12.js +22 -23
  344. package/dist/esm/scripts/moveToFinished-14.js +30 -32
  345. package/dist/esm/scripts/obliterate-2.js +15 -13
  346. package/dist/esm/scripts/pause-7.js +31 -5
  347. package/dist/esm/scripts/promote-9.js +10 -14
  348. package/dist/esm/scripts/removeChildDependency-1.js +9 -13
  349. package/dist/esm/scripts/removeJob-2.js +9 -13
  350. package/dist/esm/scripts/removeUnprocessedChildren-2.js +9 -13
  351. package/dist/esm/scripts/reprocessJob-8.js +8 -12
  352. package/dist/esm/scripts/retryJob-11.js +3 -23
  353. package/dist/esm/scripts/updateJobScheduler-12.js +9 -22
  354. package/dist/esm/tsconfig.tsbuildinfo +1 -1
  355. package/dist/esm/types/job-options.d.ts +11 -45
  356. package/dist/esm/types/job-scheduler-template-options.d.ts +1 -1
  357. package/dist/esm/types/job-type.d.ts +1 -1
  358. package/dist/esm/utils/create-backend.d.ts +26 -0
  359. package/dist/esm/utils/create-backend.js +75 -0
  360. package/dist/esm/utils/index.d.ts +3 -8
  361. package/dist/esm/utils/index.js +2 -23
  362. package/dist/esm/version.d.ts +1 -1
  363. package/dist/esm/version.js +1 -1
  364. package/package.json +24 -7
  365. package/dist/cjs/classes/repeat.js +0 -203
  366. package/dist/cjs/commands/addRepeatableJob-2.lua +0 -84
  367. package/dist/cjs/commands/includes/getTargetQueueList.lua +0 -22
  368. package/dist/cjs/commands/removeRepeatable-3.lua +0 -58
  369. package/dist/cjs/commands/updateRepeatableJobMillis-1.lua +0 -28
  370. package/dist/cjs/scripts/addRepeatableJob-2.js +0 -237
  371. package/dist/cjs/scripts/removeRepeatable-3.js +0 -62
  372. package/dist/cjs/scripts/updateRepeatableJobMillis-1.js +0 -32
  373. package/dist/cjs/utils/create-scripts.js +0 -21
  374. package/dist/esm/classes/repeat.d.ts +0 -25
  375. package/dist/esm/classes/repeat.js +0 -198
  376. package/dist/esm/commands/addRepeatableJob-2.lua +0 -84
  377. package/dist/esm/commands/includes/getTargetQueueList.lua +0 -22
  378. package/dist/esm/commands/removeRepeatable-3.lua +0 -58
  379. package/dist/esm/commands/updateRepeatableJobMillis-1.lua +0 -28
  380. package/dist/esm/interfaces/repeatable-job.d.ts +0 -10
  381. package/dist/esm/scripts/addRepeatableJob-2.d.ts +0 -5
  382. package/dist/esm/scripts/addRepeatableJob-2.js +0 -234
  383. package/dist/esm/scripts/removeRepeatable-3.d.ts +0 -5
  384. package/dist/esm/scripts/removeRepeatable-3.js +0 -59
  385. package/dist/esm/scripts/updateRepeatableJobMillis-1.d.ts +0 -5
  386. package/dist/esm/scripts/updateRepeatableJobMillis-1.js +0 -29
  387. package/dist/esm/utils/create-scripts.d.ts +0 -3
  388. package/dist/esm/utils/create-scripts.js +0 -17
  389. /package/dist/cjs/interfaces/{repeatable-job.js → queue-backend.js} +0 -0
  390. /package/dist/esm/interfaces/{repeatable-job.js → queue-backend.js} +0 -0
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.finishedErrors = finishedErrors;
4
+ const enums_1 = require("../enums");
5
+ const unrecoverable_error_1 = require("./errors/unrecoverable-error");
6
+ /**
7
+ * Builds the canonical `Error` for a negative status code returned by a backend
8
+ * operation (Lua script, SQL function, …). Shared by every backend so that the
9
+ * error messages a caller sees are identical regardless of the datastore.
10
+ *
11
+ * The resulting error carries the numeric `code` so callers can branch on it.
12
+ */
13
+ function finishedErrors({ code, jobId, parentKey, command, state, }) {
14
+ let error;
15
+ switch (code) {
16
+ case enums_1.ErrorCode.JobNotExist:
17
+ error = new Error(`Missing key for job ${jobId}. ${command}`);
18
+ break;
19
+ case enums_1.ErrorCode.JobLockNotExist:
20
+ error = new Error(`Missing lock for job ${jobId}. ${command}`);
21
+ break;
22
+ case enums_1.ErrorCode.JobNotInState:
23
+ error = new Error(`Job ${jobId} is not in the ${state} state. ${command}`);
24
+ break;
25
+ case enums_1.ErrorCode.JobPendingChildren:
26
+ error = new Error(`Job ${jobId} has pending dependencies. ${command}`);
27
+ break;
28
+ case enums_1.ErrorCode.ParentJobNotExist:
29
+ error = new Error(`Missing key for parent job ${parentKey}. ${command}`);
30
+ break;
31
+ case enums_1.ErrorCode.JobLockMismatch:
32
+ error = new Error(`Lock mismatch for job ${jobId}. Cmd ${command} from ${state}`);
33
+ break;
34
+ case enums_1.ErrorCode.ParentJobCannotBeReplaced:
35
+ error = new Error(`The parent job ${parentKey} cannot be replaced. ${command}`);
36
+ break;
37
+ case enums_1.ErrorCode.JobBelongsToJobScheduler:
38
+ error = new Error(`Job ${jobId} belongs to a job scheduler and cannot be removed directly. ${command}`);
39
+ break;
40
+ case enums_1.ErrorCode.JobHasFailedChildren:
41
+ error = new unrecoverable_error_1.UnrecoverableError(`Cannot complete job ${jobId} because it has at least one failed child. ${command}`);
42
+ break;
43
+ case enums_1.ErrorCode.SchedulerJobIdCollision:
44
+ error = new Error(`Cannot create job scheduler iteration - job ID already exists. ${command}`);
45
+ break;
46
+ case enums_1.ErrorCode.SchedulerJobSlotsBusy:
47
+ error = new Error(`Cannot create job scheduler iteration - current and next time slots already have jobs. ${command}`);
48
+ break;
49
+ default:
50
+ error = new Error(`Unknown code ${code} error for ${jobId}. ${command}`);
51
+ }
52
+ // Add the code property to the error object
53
+ error.code = code;
54
+ return error;
55
+ }
@@ -3,10 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.FlowProducer = void 0;
4
4
  const events_1 = require("events");
5
5
  const utils_1 = require("../utils");
6
- const create_scripts_1 = require("../utils/create-scripts");
6
+ const create_backend_1 = require("../utils/create-backend");
7
7
  const job_1 = require("./job");
8
- const queue_keys_1 = require("./queue-keys");
9
- const redis_connection_1 = require("./redis-connection");
10
8
  const enums_1 = require("../enums");
11
9
  /**
12
10
  * This class allows to add jobs with dependencies between them in such
@@ -17,31 +15,23 @@ const enums_1 = require("../enums");
17
15
  * All Jobs can be in different queues, either children or parents,
18
16
  */
19
17
  class FlowProducer extends events_1.EventEmitter {
20
- constructor(opts = { connection: {} }, Connection = redis_connection_1.RedisConnection) {
18
+ constructor(opts = { connection: {} }, backendFactory = (0, create_backend_1.getDefaultBackendFactory)()) {
21
19
  super();
22
20
  this.opts = opts;
23
- /**
24
- * Cache of lightweight queue-like objects keyed by `${prefix}:${queueName}`.
25
- * Each entry carries a single shared Scripts instance that is reused by all
26
- * jobs added to that queue during the FlowProducer's lifetime, avoiding a
27
- * redundant Scripts allocation per node/job.
28
- */
29
- this.queues = new Map();
30
- this.opts = Object.assign({ prefix: 'bull' }, opts);
31
- this.connection = new Connection(opts.connection, {
32
- shared: (0, utils_1.isRedisInstance)(opts.connection),
33
- blocking: false,
34
- skipVersionCheck: opts.skipVersionCheck,
35
- skipWaitingForReady: opts.skipWaitingForReady,
21
+ this.opts = Object.assign({}, opts);
22
+ // The flow producer is not bound to a single queue: each flow entry carries
23
+ // its own queue identity, so the backend is created with an empty name.
24
+ this.backend = backendFactory('', this.opts);
25
+ this.backend.on('error', (error) => {
26
+ if (this.listenerCount('error') > 0) {
27
+ this.emit('error', error);
28
+ }
36
29
  });
37
- (0, utils_1.forwardConnectionError)(this, this.connection);
38
- this.connection.on('close', () => {
39
- this.queues.clear();
30
+ this.backend.on('close', () => {
40
31
  if (!this.closing) {
41
32
  this.emit('ioredis:close');
42
33
  }
43
34
  });
44
- this.queueKeys = new queue_keys_1.QueueKeys(opts.prefix);
45
35
  if (opts === null || opts === void 0 ? void 0 : opts.telemetry) {
46
36
  this.telemetry = opts.telemetry;
47
37
  }
@@ -61,12 +51,6 @@ class FlowProducer extends events_1.EventEmitter {
61
51
  super.once(event, listener);
62
52
  return this;
63
53
  }
64
- /**
65
- * Returns a promise that resolves to a redis client. Normally used only by subclasses.
66
- */
67
- get client() {
68
- return this.connection.client;
69
- }
70
54
  /**
71
55
  * Helper to easily extend Job class calls.
72
56
  */
@@ -74,7 +58,19 @@ class FlowProducer extends events_1.EventEmitter {
74
58
  return job_1.Job;
75
59
  }
76
60
  waitUntilReady() {
77
- return this.client;
61
+ return this.backend.waitUntilReady();
62
+ }
63
+ /**
64
+ * Returns the datastore backend that powers this flow producer.
65
+ *
66
+ * The backend owns its connection and exposes every datastore-agnostic
67
+ * operation through {@link IQueueBackend}. Datastore-specific escape hatches
68
+ * (e.g. the raw Redis client) live on the concrete backend implementation,
69
+ * and are exposed here when the flow producer is parameterized on that
70
+ * concrete backend type (the default is the Redis backend).
71
+ */
72
+ getBackend() {
73
+ return this.backend;
78
74
  }
79
75
  /**
80
76
  * Adds a flow.
@@ -87,13 +83,15 @@ class FlowProducer extends events_1.EventEmitter {
87
83
  * @param opts - options that will be applied to the flow object.
88
84
  */
89
85
  async add(flow, opts) {
90
- var _a;
91
86
  if (this.closing) {
92
87
  return;
93
88
  }
94
- const client = await this.connection.client;
95
- const multi = client.multi();
96
- const parentOpts = (_a = flow === null || flow === void 0 ? void 0 : flow.opts) === null || _a === void 0 ? void 0 : _a.parent;
89
+ this.validateFlowJobs([flow]);
90
+ // Ensure the backend (and thus the connection) is ready before building
91
+ // the per-node queue contexts used to create jobs.
92
+ await this.backend.waitUntilReady();
93
+ const flowOpts = flow === null || flow === void 0 ? void 0 : flow.opts;
94
+ const parentOpts = flowOpts && 'parent' in flowOpts ? flowOpts.parent : undefined;
97
95
  const parentKey = (0, utils_1.getParentKey)(parentOpts);
98
96
  const parentDependenciesKey = parentKey
99
97
  ? `${parentKey}:dependencies`
@@ -102,8 +100,9 @@ class FlowProducer extends events_1.EventEmitter {
102
100
  span === null || span === void 0 ? void 0 : span.setAttributes({
103
101
  [enums_1.TelemetryAttributes.FlowName]: flow.name,
104
102
  });
103
+ const entries = [];
105
104
  const jobsTree = await this.addNode({
106
- multi,
105
+ entries,
107
106
  node: flow,
108
107
  queuesOpts: opts === null || opts === void 0 ? void 0 : opts.queuesOptions,
109
108
  parent: {
@@ -111,7 +110,7 @@ class FlowProducer extends events_1.EventEmitter {
111
110
  parentDependenciesKey,
112
111
  },
113
112
  });
114
- const results = (await multi.exec());
113
+ const results = await this.backend.addFlow(entries);
115
114
  const [result] = results || [];
116
115
  if (result) {
117
116
  const [err, jobId] = result;
@@ -124,9 +123,6 @@ class FlowProducer extends events_1.EventEmitter {
124
123
  if (typeof jobId === 'string') {
125
124
  jobsTree.job.id = jobId;
126
125
  }
127
- else if (typeof jobId === 'number') {
128
- jobsTree.job.id = jobId.toString();
129
- }
130
126
  }
131
127
  return jobsTree;
132
128
  });
@@ -140,13 +136,13 @@ class FlowProducer extends events_1.EventEmitter {
140
136
  if (this.closing) {
141
137
  return;
142
138
  }
143
- const client = await this.connection.client;
139
+ await this.backend.waitUntilReady();
144
140
  const updatedOpts = Object.assign({
145
141
  depth: 10,
146
142
  maxChildren: 20,
147
143
  prefix: this.opts.prefix,
148
144
  }, opts);
149
- const jobsTree = this.getNode(client, updatedOpts);
145
+ const jobsTree = this.getNode(updatedOpts);
150
146
  return jobsTree;
151
147
  }
152
148
  /**
@@ -156,8 +152,9 @@ class FlowProducer extends events_1.EventEmitter {
156
152
  * Whenever the children of a given parent are completed, the parent
157
153
  * will be processed, being able to access the children's result data.
158
154
  *
159
- * All Jobs can be in different queues, either children or parents.
160
- * If a flow fails to be added, other flows in the batch may still be added.
155
+ * All Jobs can be in different queues, either children or parents,
156
+ * however this call would be atomic, either it fails and no jobs will
157
+ * be added to the queues, or it succeeds and all jobs will be added.
161
158
  *
162
159
  * @param flows - an array of objects with a tree-like structure where children jobs
163
160
  * will be processed before their parents.
@@ -166,36 +163,29 @@ class FlowProducer extends events_1.EventEmitter {
166
163
  if (this.closing) {
167
164
  return;
168
165
  }
169
- const client = await this.connection.client;
170
- const multi = client.multi();
166
+ this.validateFlowJobs(flows);
167
+ // Ensure the backend (and thus the connection) is ready before building
168
+ // the per-node queue contexts used to create jobs.
169
+ await this.backend.waitUntilReady();
171
170
  return (0, utils_1.trace)(this.telemetry, enums_1.SpanKind.PRODUCER, '', 'addBulkFlows', '', async (span) => {
172
- var _a, _b;
173
171
  span === null || span === void 0 ? void 0 : span.setAttributes({
174
172
  [enums_1.TelemetryAttributes.BulkCount]: flows.length,
175
173
  [enums_1.TelemetryAttributes.BulkNames]: flows
176
174
  .map(flow => flow.name)
177
175
  .join(','),
178
176
  });
179
- const jobsTrees = await this.addNodes(multi, flows);
180
- const results = (await multi.exec());
177
+ const entries = [];
178
+ const jobsTrees = await this.addNodes(entries, flows);
179
+ const results = await this.backend.addFlow(entries);
181
180
  for (let index = 0; index < jobsTrees.length; ++index) {
182
181
  const result = results === null || results === void 0 ? void 0 : results[index];
183
182
  if (!result) {
184
183
  continue;
185
184
  }
186
185
  const [err, jobId] = result;
187
- if (err) {
188
- throw err;
189
- }
190
- if (typeof jobId === 'number' && jobId < 0) {
191
- throw this.toFlowError(jobId, (0, utils_1.getParentKey)((_b = (_a = flows[index]) === null || _a === void 0 ? void 0 : _a.opts) === null || _b === void 0 ? void 0 : _b.parent));
192
- }
193
- if (typeof jobId === 'string') {
186
+ if (!err && typeof jobId === 'string') {
194
187
  jobsTrees[index].job.id = jobId;
195
188
  }
196
- else if (typeof jobId === 'number') {
197
- jobsTrees[index].job.id = jobId.toString();
198
- }
199
189
  }
200
190
  return jobsTrees;
201
191
  });
@@ -211,10 +201,10 @@ class FlowProducer extends events_1.EventEmitter {
211
201
  * @param parent - parent data sent to children to create the "links" to their parent
212
202
  * @returns
213
203
  */
214
- async addNode({ multi, node, parent, queuesOpts, }) {
204
+ async addNode({ entries, node, parent, queuesOpts, }) {
215
205
  var _a, _b;
216
206
  const prefix = node.prefix || this.opts.prefix;
217
- const queue = this.queueFromNode(node, new queue_keys_1.QueueKeys(prefix), prefix);
207
+ const queue = this.queueFromNode(node, prefix);
218
208
  const queueOpts = queuesOpts && queuesOpts[node.queueName];
219
209
  const jobsOpts = (_a = queueOpts === null || queueOpts === void 0 ? void 0 : queueOpts.defaultJobOptions) !== null && _a !== void 0 ? _a : {};
220
210
  const jobId = ((_b = node.opts) === null || _b === void 0 ? void 0 : _b.jobId) || (0, utils_1.randomUUID)();
@@ -242,20 +232,21 @@ class FlowProducer extends events_1.EventEmitter {
242
232
  if (node.children && node.children.length > 0) {
243
233
  // Create the parent job, it will be a job in status "waiting-children".
244
234
  const parentId = jobId;
245
- const queueKeysParent = new queue_keys_1.QueueKeys(node.prefix || this.opts.prefix);
246
- await job.addJob(multi, {
235
+ await this.collectFlowEntry(entries, job, {
247
236
  parentDependenciesKey: parent === null || parent === void 0 ? void 0 : parent.parentDependenciesKey,
248
237
  addToWaitingChildren: true,
249
238
  parentKey,
250
239
  });
251
- const parentDependenciesKey = `${queueKeysParent.toKey(node.queueName, parentId)}:dependencies`;
240
+ // Queue identity is owned by the backend (the `queue` object above is
241
+ // bound to this node's queue via the backend's `forQueue`).
242
+ const parentDependenciesKey = `${queue.toKey(parentId)}:dependencies`;
252
243
  const children = await this.addChildren({
253
- multi,
244
+ entries,
254
245
  nodes: node.children,
255
246
  parent: {
256
247
  parentOpts: {
257
248
  id: parentId,
258
- queue: queueKeysParent.getQueueQualifiedName(node.queueName),
249
+ queue: queue.qualifiedName,
259
250
  },
260
251
  parentDependenciesKey,
261
252
  },
@@ -264,7 +255,7 @@ class FlowProducer extends events_1.EventEmitter {
264
255
  return { job, children };
265
256
  }
266
257
  else {
267
- await job.addJob(multi, {
258
+ await this.collectFlowEntry(entries, job, {
268
259
  parentDependenciesKey: parent === null || parent === void 0 ? void 0 : parent.parentDependenciesKey,
269
260
  parentKey,
270
261
  });
@@ -282,16 +273,24 @@ class FlowProducer extends events_1.EventEmitter {
282
273
  * @param nodes - the nodes representing jobs to be added to some queue
283
274
  * @returns
284
275
  */
285
- addNodes(multi, nodes) {
276
+ /**
277
+ * Collects a single job insert for a flow, preserving the same await point
278
+ * as the previous transaction-based insert so that the relative order of
279
+ * entries (in particular, roots before their descendants) is unchanged.
280
+ */
281
+ async collectFlowEntry(entries, job, parentOpts) {
282
+ entries.push(job.toFlowEntry(parentOpts));
283
+ }
284
+ addNodes(entries, nodes) {
286
285
  return Promise.all(nodes.map(node => {
287
- var _a;
288
- const parentOpts = (_a = node === null || node === void 0 ? void 0 : node.opts) === null || _a === void 0 ? void 0 : _a.parent;
286
+ const nodeOpts = node === null || node === void 0 ? void 0 : node.opts;
287
+ const parentOpts = nodeOpts && 'parent' in nodeOpts ? nodeOpts.parent : undefined;
289
288
  const parentKey = (0, utils_1.getParentKey)(parentOpts);
290
289
  const parentDependenciesKey = parentKey
291
290
  ? `${parentKey}:dependencies`
292
291
  : undefined;
293
292
  return this.addNode({
294
- multi,
293
+ entries,
295
294
  node,
296
295
  parent: {
297
296
  parentOpts,
@@ -300,8 +299,8 @@ class FlowProducer extends events_1.EventEmitter {
300
299
  });
301
300
  }));
302
301
  }
303
- async getNode(client, node) {
304
- const queue = this.queueFromNode(node, new queue_keys_1.QueueKeys(node.prefix), node.prefix);
302
+ async getNode(node) {
303
+ const queue = this.queueFromNode(node, node.prefix);
305
304
  const job = await this.Job.fromId(queue, node.id);
306
305
  if (job) {
307
306
  const { processed = {}, unprocessed = [], failed = [], ignored = {}, } = await job.getDependencies({
@@ -326,7 +325,7 @@ class FlowProducer extends events_1.EventEmitter {
326
325
  failed.length;
327
326
  const newDepth = node.depth - 1;
328
327
  if (childrenCount > 0 && newDepth) {
329
- const children = await this.getChildren(client, [...processedKeys, ...unprocessed, ...failed, ...ignoredKeys], newDepth, node.maxChildren);
328
+ const children = await this.getChildren([...processedKeys, ...unprocessed, ...failed, ...ignoredKeys], newDepth, node.maxChildren);
330
329
  return { job, children };
331
330
  }
332
331
  else {
@@ -334,13 +333,26 @@ class FlowProducer extends events_1.EventEmitter {
334
333
  }
335
334
  }
336
335
  }
337
- addChildren({ multi, nodes, parent, queuesOpts }) {
338
- return Promise.all(nodes.map(node => this.addNode({ multi, node, parent, queuesOpts })));
336
+ validateFlowJobs(nodes) {
337
+ for (const node of nodes) {
338
+ const children = node.children;
339
+ if (children && children.length > 0) {
340
+ const nodeOpts = node.opts;
341
+ const hasDeduplication = nodeOpts && 'deduplication' in nodeOpts && nodeOpts.deduplication;
342
+ if (hasDeduplication) {
343
+ throw new Error('Deduplication options cannot be used on flow nodes with children');
344
+ }
345
+ this.validateFlowJobs(children);
346
+ }
347
+ }
348
+ }
349
+ addChildren({ entries, nodes, parent, queuesOpts }) {
350
+ return Promise.all(nodes.map(node => this.addNode({ entries, node, parent, queuesOpts })));
339
351
  }
340
- getChildren(client, childrenKeys, depth, maxChildren) {
352
+ getChildren(childrenKeys, depth, maxChildren) {
341
353
  const getChild = (key) => {
342
- const [prefix, queueName, id] = key.split(':');
343
- return this.getNode(client, {
354
+ const { prefix, queueName, id } = this.backend.parseNodeKey(key);
355
+ return this.getNode({
344
356
  id,
345
357
  queueName,
346
358
  prefix,
@@ -355,45 +367,31 @@ class FlowProducer extends events_1.EventEmitter {
355
367
  * required to create jobs in any queue.
356
368
  *
357
369
  * @param node - The flow node containing the queue name and other job options.
358
- * @param queueKeys - The queue keys helper used to resolve key names.
359
- * @param prefix - The Redis key prefix used for the queue.
360
- * @returns A queue-like object with the client, keys, and options needed to create jobs.
370
+ * @param prefix - The key prefix for the queue (honored by the Redis backend only).
371
+ * @returns A queue-like object with the keys, identity and backend needed to create jobs.
361
372
  */
362
- queueFromNode(node, queueKeys, prefix) {
363
- const cacheKey = `${prefix}:${node.queueName}`;
364
- const cached = this.queues.get(cacheKey);
365
- if (cached) {
366
- return cached;
367
- }
368
- const flowProducer = this;
369
- const queue = {
370
- client: this.connection.client,
373
+ queueFromNode(node, prefix) {
374
+ // Queue identity and key building are owned by the backend (the Redis
375
+ // backend encodes the key `prefix`; other backends format their own
376
+ // identity). The flow's own backend is queue-agnostic, so we ask it for a
377
+ // sibling bound to this node's queue.
378
+ const backend = this.backend.forQueue(node.queueName, prefix);
379
+ return {
371
380
  name: node.queueName,
372
- keys: queueKeys.getKeys(node.queueName),
373
- toKey: (type) => queueKeys.toKey(node.queueName, type),
381
+ keys: backend.keys,
382
+ toKey: (type) => backend.toKey(type),
374
383
  opts: { prefix, connection: {} },
375
- qualifiedName: queueKeys.getQueueQualifiedName(node.queueName),
376
- get closing() {
377
- return flowProducer.closing;
384
+ qualifiedName: backend.qualifiedName,
385
+ closing: this.closing,
386
+ backend,
387
+ waitUntilReady: async () => {
388
+ await this.backend.waitUntilReady();
378
389
  },
379
- waitUntilReady: async () => this.connection.client,
380
390
  removeListener: this.removeListener.bind(this),
381
391
  emit: this.emit.bind(this),
382
392
  on: this.on.bind(this),
383
- get redisVersion() {
384
- return flowProducer.connection.redisVersion;
385
- },
386
- get databaseType() {
387
- return flowProducer.connection.databaseType;
388
- },
389
393
  trace: async () => { },
390
394
  };
391
- // Build the shared Scripts instance once per queue so that every job
392
- // created from this queue-like object reuses it instead of allocating
393
- // its own.
394
- queue.scripts = (0, create_scripts_1.createScripts)(queue);
395
- this.queues.set(cacheKey, queue);
396
- return queue;
397
395
  }
398
396
  /**
399
397
  * Translates numeric addJob Lua error codes returned by root flow exec.
@@ -422,8 +420,7 @@ class FlowProducer extends events_1.EventEmitter {
422
420
  */
423
421
  async close() {
424
422
  if (!this.closing) {
425
- this.queues.clear();
426
- this.closing = this.connection.close();
423
+ this.closing = this.backend.close();
427
424
  }
428
425
  await this.closing;
429
426
  }
@@ -432,7 +429,7 @@ class FlowProducer extends events_1.EventEmitter {
432
429
  * Force disconnects a connection.
433
430
  */
434
431
  disconnect() {
435
- return this.connection.disconnect();
432
+ return this.backend.disconnect();
436
433
  }
437
434
  }
438
435
  exports.FlowProducer = FlowProducer;
@@ -24,7 +24,6 @@ tslib_1.__exportStar(require("./queue-getters"), exports);
24
24
  tslib_1.__exportStar(require("./queue-keys"), exports);
25
25
  tslib_1.__exportStar(require("./queue"), exports);
26
26
  tslib_1.__exportStar(require("./redis-connection"), exports);
27
- tslib_1.__exportStar(require("./repeat"), exports);
28
27
  tslib_1.__exportStar(require("./sandbox"), exports);
29
- tslib_1.__exportStar(require("./scripts"), exports);
28
+ tslib_1.__exportStar(require("./redis-queue-backend"), exports);
30
29
  tslib_1.__exportStar(require("./worker"), exports);