bullmq 5.81.2 → 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.
- package/README.md +2 -2
- package/dist/cjs/classes/bun-redis-client.js +8 -2
- package/dist/cjs/classes/finished-errors.js +55 -0
- package/dist/cjs/classes/flow-producer.js +106 -109
- package/dist/cjs/classes/index.js +1 -2
- package/dist/cjs/classes/job-scheduler.js +120 -43
- package/dist/cjs/classes/job.js +136 -305
- package/dist/cjs/classes/queue-base.js +35 -41
- package/dist/cjs/classes/queue-events-producer.js +4 -9
- package/dist/cjs/classes/queue-events.js +10 -21
- package/dist/cjs/classes/queue-getters.js +47 -72
- package/dist/cjs/classes/queue.js +57 -215
- package/dist/cjs/classes/redis-connection.js +28 -2
- package/dist/cjs/classes/{scripts.js → redis-queue-backend.js} +838 -195
- package/dist/cjs/classes/worker.js +103 -139
- package/dist/cjs/commands/addJobScheduler-11.lua +0 -4
- package/dist/cjs/commands/addStandardJob-9.lua +7 -5
- package/dist/cjs/commands/changePriority-7.lua +10 -7
- package/dist/cjs/commands/getCountsPerPriority-4.lua +1 -8
- package/dist/cjs/commands/includes/deduplicateJob.lua +5 -8
- package/dist/cjs/commands/includes/deduplicateJobWithoutReplace.lua +13 -18
- package/dist/cjs/commands/includes/fetchNextJob.lua +4 -4
- package/dist/cjs/commands/includes/getQueueMetadata.lua +21 -0
- package/dist/cjs/commands/includes/getWaitPlusPrioritizedCount.lua +10 -0
- package/dist/cjs/commands/includes/moveJobToWait.lua +3 -3
- package/dist/cjs/commands/includes/moveParentToWait.lua +4 -5
- package/dist/cjs/commands/includes/removeParentDependencyKey.lua +4 -4
- package/dist/cjs/commands/includes/storeAndEnqueueJob.lua +3 -3
- package/dist/cjs/commands/includes/storeDeduplicatedNextJob.lua +4 -7
- package/dist/cjs/commands/moveJobFromActiveToWait-9.lua +3 -3
- package/dist/cjs/commands/moveJobsToWait-8.lua +3 -3
- package/dist/cjs/commands/moveStalledJobsToWait-9.lua +0 -1
- package/dist/cjs/commands/moveToActive-11.lua +4 -4
- package/dist/cjs/commands/obliterate-2.lua +7 -0
- package/dist/cjs/commands/pause-7.lua +27 -5
- package/dist/cjs/commands/promote-9.lua +5 -5
- package/dist/cjs/commands/reprocessJob-8.lua +3 -3
- package/dist/cjs/commands/retryJob-11.lua +3 -4
- package/dist/cjs/commands/updateJobScheduler-12.lua +1 -13
- package/dist/cjs/enums/telemetry-attributes.js +1 -8
- package/dist/cjs/index.js +3 -1
- package/dist/cjs/interfaces/index.js +1 -1
- package/dist/cjs/postgres/commands/add_flow.sql +3 -0
- package/dist/cjs/postgres/commands/add_job.sql +5 -0
- package/dist/cjs/postgres/commands/add_job_scheduler.sql +6 -0
- package/dist/cjs/postgres/commands/add_jobs_bulk.sql +3 -0
- package/dist/cjs/postgres/commands/add_log.sql +14 -0
- package/dist/cjs/postgres/commands/change_delay.sql +3 -0
- package/dist/cjs/postgres/commands/change_priority.sql +3 -0
- package/dist/cjs/postgres/commands/clean.sql +3 -0
- package/dist/cjs/postgres/commands/clear_logs.sql +9 -0
- package/dist/cjs/postgres/commands/collect_metrics.sql +4 -0
- package/dist/cjs/postgres/commands/delete_deduplication_key.sql +6 -0
- package/dist/cjs/postgres/commands/drain.sql +2 -0
- package/dist/cjs/postgres/commands/extend_lock.sql +3 -0
- package/dist/cjs/postgres/commands/extend_locks.sql +25 -0
- package/dist/cjs/postgres/commands/get_client_list.sql +11 -0
- package/dist/cjs/postgres/commands/get_counts.sql +13 -0
- package/dist/cjs/postgres/commands/get_counts_per_priority.sql +14 -0
- package/dist/cjs/postgres/commands/get_deduplication_job_id.sql +7 -0
- package/dist/cjs/postgres/commands/get_dependencies.sql +8 -0
- package/dist/cjs/postgres/commands/get_dependencies_page.sql +7 -0
- package/dist/cjs/postgres/commands/get_dependency_counts.sql +9 -0
- package/dist/cjs/postgres/commands/get_ignored_children_failures.sql +7 -0
- package/dist/cjs/postgres/commands/get_job_data.sql +2 -0
- package/dist/cjs/postgres/commands/get_job_logs_asc.sql +6 -0
- package/dist/cjs/postgres/commands/get_job_logs_count.sql +2 -0
- package/dist/cjs/postgres/commands/get_job_logs_desc.sql +6 -0
- package/dist/cjs/postgres/commands/get_job_scheduler.sql +6 -0
- package/dist/cjs/postgres/commands/get_job_schedulers_count.sql +2 -0
- package/dist/cjs/postgres/commands/get_job_schedulers_range.sql +10 -0
- package/dist/cjs/postgres/commands/get_metrics.sql +14 -0
- package/dist/cjs/postgres/commands/get_processed_children_values.sql +8 -0
- package/dist/cjs/postgres/commands/get_queue_meta.sql +2 -0
- package/dist/cjs/postgres/commands/get_queue_meta_field.sql +2 -0
- package/dist/cjs/postgres/commands/get_queue_meta_fields.sql +3 -0
- package/dist/cjs/postgres/commands/get_range.sql +3 -0
- package/dist/cjs/postgres/commands/get_rate_limit_ttl.sql +3 -0
- package/dist/cjs/postgres/commands/get_state.sql +2 -0
- package/dist/cjs/postgres/commands/has_queue_meta_field.sql +4 -0
- package/dist/cjs/postgres/commands/has_waiting_job.sql +11 -0
- package/dist/cjs/postgres/commands/is_finished.sql +4 -0
- package/dist/cjs/postgres/commands/is_job_in_state.sql +6 -0
- package/dist/cjs/postgres/commands/is_job_in_wait.sql +15 -0
- package/dist/cjs/postgres/commands/is_job_prioritized.sql +6 -0
- package/dist/cjs/postgres/commands/is_job_scheduler.sql +4 -0
- package/dist/cjs/postgres/commands/is_maxed.sql +10 -0
- package/dist/cjs/postgres/commands/listen_events.sql +3 -0
- package/dist/cjs/postgres/commands/listen_jobs.sql +4 -0
- package/dist/cjs/postgres/commands/move_active_to_wait.sql +4 -0
- package/dist/cjs/postgres/commands/move_stalled_jobs_to_wait.sql +4 -0
- package/dist/cjs/postgres/commands/move_to_active.sql +4 -0
- package/dist/cjs/postgres/commands/move_to_completed.sql +4 -0
- package/dist/cjs/postgres/commands/move_to_completed_fetch.sql +9 -0
- package/dist/cjs/postgres/commands/move_to_delayed.sql +4 -0
- package/dist/cjs/postgres/commands/move_to_failed.sql +4 -0
- package/dist/cjs/postgres/commands/move_to_failed_fetch.sql +9 -0
- package/dist/cjs/postgres/commands/move_to_waiting_children.sql +3 -0
- package/dist/cjs/postgres/commands/next_delay.sql +2 -0
- package/dist/cjs/postgres/commands/next_signal.sql +3 -0
- package/dist/cjs/postgres/commands/obliterate.sql +4 -0
- package/dist/cjs/postgres/commands/paginate_dependencies.sql +19 -0
- package/dist/cjs/postgres/commands/pause.sql +2 -0
- package/dist/cjs/postgres/commands/promote.sql +3 -0
- package/dist/cjs/postgres/commands/promote_jobs.sql +3 -0
- package/dist/cjs/postgres/commands/publish_event.sql +3 -0
- package/dist/cjs/postgres/commands/read_events.sql +6 -0
- package/dist/cjs/postgres/commands/read_events_max.sql +3 -0
- package/dist/cjs/postgres/commands/remove.sql +3 -0
- package/dist/cjs/postgres/commands/remove_child_dependency.sql +4 -0
- package/dist/cjs/postgres/commands/remove_deduplication_key.sql +9 -0
- package/dist/cjs/postgres/commands/remove_job_scheduler.sql +3 -0
- package/dist/cjs/postgres/commands/remove_queue_meta_fields.sql +2 -0
- package/dist/cjs/postgres/commands/remove_rate_limit.sql +6 -0
- package/dist/cjs/postgres/commands/remove_unprocessed_children.sql +3 -0
- package/dist/cjs/postgres/commands/reprocess_job.sql +4 -0
- package/dist/cjs/postgres/commands/retry_job.sql +3 -0
- package/dist/cjs/postgres/commands/retry_jobs.sql +3 -0
- package/dist/cjs/postgres/commands/set_queue_meta.sql +4 -0
- package/dist/cjs/postgres/commands/set_rate_limit.sql +3 -0
- package/dist/cjs/postgres/commands/trim_logs.sql +3 -0
- package/dist/cjs/postgres/commands/update_data.sql +3 -0
- package/dist/cjs/postgres/commands/update_job_scheduler.sql +5 -0
- package/dist/cjs/postgres/commands/update_progress.sql +3 -0
- package/dist/cjs/postgres/create-postgres-backend.js +46 -0
- package/dist/cjs/postgres/index.js +23 -0
- package/dist/cjs/postgres/migrations/0001_schema.sql +348 -0
- package/dist/cjs/postgres/migrations/0002_functions.sql +3473 -0
- package/dist/cjs/postgres/migrations/index.js +26 -0
- package/dist/cjs/postgres/migrator.js +229 -0
- package/dist/cjs/postgres/pg-types.js +14 -0
- package/dist/cjs/postgres/postgres-connection.js +211 -0
- package/dist/cjs/postgres/postgres-queue-backend.js +1705 -0
- package/dist/cjs/postgres/sql-loader.js +47 -0
- package/dist/cjs/scripts/addDelayedJob-6.js +25 -57
- package/dist/cjs/scripts/addJobScheduler-11.js +11 -18
- package/dist/cjs/scripts/addParentJob-6.js +20 -49
- package/dist/cjs/scripts/addPrioritizedJob-9.js +25 -57
- package/dist/cjs/scripts/addStandardJob-9.js +31 -61
- package/dist/cjs/scripts/changePriority-7.js +15 -16
- package/dist/cjs/scripts/cleanJobsInSet-3.js +9 -13
- package/dist/cjs/scripts/drain-5.js +9 -13
- package/dist/cjs/scripts/getCountsPerPriority-4.js +1 -13
- package/dist/cjs/scripts/index.js +0 -3
- package/dist/cjs/scripts/moveJobFromActiveToWait-9.js +8 -12
- package/dist/cjs/scripts/moveJobsToWait-8.js +8 -12
- package/dist/cjs/scripts/moveStalledJobsToWait-9.js +24 -28
- package/dist/cjs/scripts/moveToActive-11.js +22 -23
- package/dist/cjs/scripts/moveToDelayed-12.js +22 -23
- package/dist/cjs/scripts/moveToFinished-14.js +30 -32
- package/dist/cjs/scripts/obliterate-2.js +15 -13
- package/dist/cjs/scripts/pause-7.js +31 -5
- package/dist/cjs/scripts/promote-9.js +10 -14
- package/dist/cjs/scripts/removeChildDependency-1.js +9 -13
- package/dist/cjs/scripts/removeJob-2.js +9 -13
- package/dist/cjs/scripts/removeUnprocessedChildren-2.js +9 -13
- package/dist/cjs/scripts/reprocessJob-8.js +8 -12
- package/dist/cjs/scripts/retryJob-11.js +3 -23
- package/dist/cjs/scripts/updateJobScheduler-12.js +9 -22
- package/dist/cjs/tsconfig-cjs.tsbuildinfo +1 -1
- package/dist/cjs/utils/create-backend.js +81 -0
- package/dist/cjs/utils/index.js +4 -25
- package/dist/cjs/version.js +1 -1
- package/dist/esm/classes/bun-redis-client.js +8 -2
- package/dist/esm/classes/finished-errors.d.ts +14 -0
- package/dist/esm/classes/finished-errors.js +52 -0
- package/dist/esm/classes/flow-producer.d.ts +45 -29
- package/dist/esm/classes/flow-producer.js +107 -110
- package/dist/esm/classes/index.d.ts +1 -2
- package/dist/esm/classes/index.js +1 -2
- package/dist/esm/classes/job-scheduler.d.ts +13 -4
- package/dist/esm/classes/job-scheduler.js +117 -43
- package/dist/esm/classes/job.d.ts +25 -60
- package/dist/esm/classes/job.js +137 -306
- package/dist/esm/classes/queue-base.d.ts +19 -20
- package/dist/esm/classes/queue-base.js +36 -42
- package/dist/esm/classes/queue-events-producer.d.ts +2 -3
- package/dist/esm/classes/queue-events-producer.js +4 -9
- package/dist/esm/classes/queue-events.d.ts +2 -19
- package/dist/esm/classes/queue-events.js +11 -22
- package/dist/esm/classes/queue-getters.d.ts +4 -5
- package/dist/esm/classes/queue-getters.js +48 -73
- package/dist/esm/classes/queue.d.ts +19 -60
- package/dist/esm/classes/queue.js +57 -215
- package/dist/esm/classes/redis-connection.js +28 -2
- package/dist/esm/classes/{scripts.d.ts → redis-queue-backend.d.ts} +227 -52
- package/dist/esm/classes/{scripts.js → redis-queue-backend.js} +837 -194
- package/dist/esm/classes/worker.d.ts +15 -15
- package/dist/esm/classes/worker.js +105 -141
- package/dist/esm/commands/addJobScheduler-11.lua +0 -4
- package/dist/esm/commands/addStandardJob-9.lua +7 -5
- package/dist/esm/commands/changePriority-7.lua +10 -7
- package/dist/esm/commands/getCountsPerPriority-4.lua +1 -8
- package/dist/esm/commands/includes/deduplicateJob.lua +5 -8
- package/dist/esm/commands/includes/deduplicateJobWithoutReplace.lua +13 -18
- package/dist/esm/commands/includes/fetchNextJob.lua +4 -4
- package/dist/esm/commands/includes/getQueueMetadata.lua +21 -0
- package/dist/esm/commands/includes/getWaitPlusPrioritizedCount.lua +10 -0
- package/dist/esm/commands/includes/moveJobToWait.lua +3 -3
- package/dist/esm/commands/includes/moveParentToWait.lua +4 -5
- package/dist/esm/commands/includes/removeParentDependencyKey.lua +4 -4
- package/dist/esm/commands/includes/storeAndEnqueueJob.lua +3 -3
- package/dist/esm/commands/includes/storeDeduplicatedNextJob.lua +4 -7
- package/dist/esm/commands/moveJobFromActiveToWait-9.lua +3 -3
- package/dist/esm/commands/moveJobsToWait-8.lua +3 -3
- package/dist/esm/commands/moveStalledJobsToWait-9.lua +0 -1
- package/dist/esm/commands/moveToActive-11.lua +4 -4
- package/dist/esm/commands/obliterate-2.lua +7 -0
- package/dist/esm/commands/pause-7.lua +27 -5
- package/dist/esm/commands/promote-9.lua +5 -5
- package/dist/esm/commands/reprocessJob-8.lua +3 -3
- package/dist/esm/commands/retryJob-11.lua +3 -4
- package/dist/esm/commands/updateJobScheduler-12.lua +1 -13
- package/dist/esm/enums/telemetry-attributes.d.ts +1 -8
- package/dist/esm/enums/telemetry-attributes.js +1 -8
- package/dist/esm/index.d.ts +2 -1
- package/dist/esm/index.js +3 -1
- package/dist/esm/interfaces/base-job-options.d.ts +0 -5
- package/dist/esm/interfaces/flow-job.d.ts +20 -7
- package/dist/esm/interfaces/index.d.ts +1 -1
- package/dist/esm/interfaces/index.js +1 -1
- package/dist/esm/interfaces/job-json.d.ts +6 -30
- package/dist/esm/interfaces/minimal-job.d.ts +2 -2
- package/dist/esm/interfaces/minimal-queue.d.ts +16 -11
- package/dist/esm/interfaces/queue-backend.d.ts +538 -0
- package/dist/esm/interfaces/queue-options.d.ts +26 -8
- package/dist/esm/interfaces/repeat-options.d.ts +14 -2
- package/dist/esm/interfaces/script-queue-context.d.ts +6 -0
- package/dist/esm/interfaces/telemetry.d.ts +1 -1
- package/dist/esm/interfaces/worker-options.d.ts +2 -2
- package/dist/esm/postgres/commands/add_flow.sql +3 -0
- package/dist/esm/postgres/commands/add_job.sql +5 -0
- package/dist/esm/postgres/commands/add_job_scheduler.sql +6 -0
- package/dist/esm/postgres/commands/add_jobs_bulk.sql +3 -0
- package/dist/esm/postgres/commands/add_log.sql +14 -0
- package/dist/esm/postgres/commands/change_delay.sql +3 -0
- package/dist/esm/postgres/commands/change_priority.sql +3 -0
- package/dist/esm/postgres/commands/clean.sql +3 -0
- package/dist/esm/postgres/commands/clear_logs.sql +9 -0
- package/dist/esm/postgres/commands/collect_metrics.sql +4 -0
- package/dist/esm/postgres/commands/delete_deduplication_key.sql +6 -0
- package/dist/esm/postgres/commands/drain.sql +2 -0
- package/dist/esm/postgres/commands/extend_lock.sql +3 -0
- package/dist/esm/postgres/commands/extend_locks.sql +25 -0
- package/dist/esm/postgres/commands/get_client_list.sql +11 -0
- package/dist/esm/postgres/commands/get_counts.sql +13 -0
- package/dist/esm/postgres/commands/get_counts_per_priority.sql +14 -0
- package/dist/esm/postgres/commands/get_deduplication_job_id.sql +7 -0
- package/dist/esm/postgres/commands/get_dependencies.sql +8 -0
- package/dist/esm/postgres/commands/get_dependencies_page.sql +7 -0
- package/dist/esm/postgres/commands/get_dependency_counts.sql +9 -0
- package/dist/esm/postgres/commands/get_ignored_children_failures.sql +7 -0
- package/dist/esm/postgres/commands/get_job_data.sql +2 -0
- package/dist/esm/postgres/commands/get_job_logs_asc.sql +6 -0
- package/dist/esm/postgres/commands/get_job_logs_count.sql +2 -0
- package/dist/esm/postgres/commands/get_job_logs_desc.sql +6 -0
- package/dist/esm/postgres/commands/get_job_scheduler.sql +6 -0
- package/dist/esm/postgres/commands/get_job_schedulers_count.sql +2 -0
- package/dist/esm/postgres/commands/get_job_schedulers_range.sql +10 -0
- package/dist/esm/postgres/commands/get_metrics.sql +14 -0
- package/dist/esm/postgres/commands/get_processed_children_values.sql +8 -0
- package/dist/esm/postgres/commands/get_queue_meta.sql +2 -0
- package/dist/esm/postgres/commands/get_queue_meta_field.sql +2 -0
- package/dist/esm/postgres/commands/get_queue_meta_fields.sql +3 -0
- package/dist/esm/postgres/commands/get_range.sql +3 -0
- package/dist/esm/postgres/commands/get_rate_limit_ttl.sql +3 -0
- package/dist/esm/postgres/commands/get_state.sql +2 -0
- package/dist/esm/postgres/commands/has_queue_meta_field.sql +4 -0
- package/dist/esm/postgres/commands/has_waiting_job.sql +11 -0
- package/dist/esm/postgres/commands/is_finished.sql +4 -0
- package/dist/esm/postgres/commands/is_job_in_state.sql +6 -0
- package/dist/esm/postgres/commands/is_job_in_wait.sql +15 -0
- package/dist/esm/postgres/commands/is_job_prioritized.sql +6 -0
- package/dist/esm/postgres/commands/is_job_scheduler.sql +4 -0
- package/dist/esm/postgres/commands/is_maxed.sql +10 -0
- package/dist/esm/postgres/commands/listen_events.sql +3 -0
- package/dist/esm/postgres/commands/listen_jobs.sql +4 -0
- package/dist/esm/postgres/commands/move_active_to_wait.sql +4 -0
- package/dist/esm/postgres/commands/move_stalled_jobs_to_wait.sql +4 -0
- package/dist/esm/postgres/commands/move_to_active.sql +4 -0
- package/dist/esm/postgres/commands/move_to_completed.sql +4 -0
- package/dist/esm/postgres/commands/move_to_completed_fetch.sql +9 -0
- package/dist/esm/postgres/commands/move_to_delayed.sql +4 -0
- package/dist/esm/postgres/commands/move_to_failed.sql +4 -0
- package/dist/esm/postgres/commands/move_to_failed_fetch.sql +9 -0
- package/dist/esm/postgres/commands/move_to_waiting_children.sql +3 -0
- package/dist/esm/postgres/commands/next_delay.sql +2 -0
- package/dist/esm/postgres/commands/next_signal.sql +3 -0
- package/dist/esm/postgres/commands/obliterate.sql +4 -0
- package/dist/esm/postgres/commands/paginate_dependencies.sql +19 -0
- package/dist/esm/postgres/commands/pause.sql +2 -0
- package/dist/esm/postgres/commands/promote.sql +3 -0
- package/dist/esm/postgres/commands/promote_jobs.sql +3 -0
- package/dist/esm/postgres/commands/publish_event.sql +3 -0
- package/dist/esm/postgres/commands/read_events.sql +6 -0
- package/dist/esm/postgres/commands/read_events_max.sql +3 -0
- package/dist/esm/postgres/commands/remove.sql +3 -0
- package/dist/esm/postgres/commands/remove_child_dependency.sql +4 -0
- package/dist/esm/postgres/commands/remove_deduplication_key.sql +9 -0
- package/dist/esm/postgres/commands/remove_job_scheduler.sql +3 -0
- package/dist/esm/postgres/commands/remove_queue_meta_fields.sql +2 -0
- package/dist/esm/postgres/commands/remove_rate_limit.sql +6 -0
- package/dist/esm/postgres/commands/remove_unprocessed_children.sql +3 -0
- package/dist/esm/postgres/commands/reprocess_job.sql +4 -0
- package/dist/esm/postgres/commands/retry_job.sql +3 -0
- package/dist/esm/postgres/commands/retry_jobs.sql +3 -0
- package/dist/esm/postgres/commands/set_queue_meta.sql +4 -0
- package/dist/esm/postgres/commands/set_rate_limit.sql +3 -0
- package/dist/esm/postgres/commands/trim_logs.sql +3 -0
- package/dist/esm/postgres/commands/update_data.sql +3 -0
- package/dist/esm/postgres/commands/update_job_scheduler.sql +5 -0
- package/dist/esm/postgres/commands/update_progress.sql +3 -0
- package/dist/esm/postgres/create-postgres-backend.d.ts +20 -0
- package/dist/esm/postgres/create-postgres-backend.js +42 -0
- package/dist/esm/postgres/index.d.ts +6 -0
- package/dist/esm/postgres/index.js +6 -0
- package/dist/esm/postgres/migrations/0001_schema.sql +348 -0
- package/dist/esm/postgres/migrations/0002_functions.sql +3473 -0
- package/dist/esm/postgres/migrations/index.d.ts +24 -0
- package/dist/esm/postgres/migrations/index.js +23 -0
- package/dist/esm/postgres/migrator.d.ts +128 -0
- package/dist/esm/postgres/migrator.js +220 -0
- package/dist/esm/postgres/pg-types.d.ts +98 -0
- package/dist/esm/postgres/pg-types.js +11 -0
- package/dist/esm/postgres/postgres-connection.d.ts +133 -0
- package/dist/esm/postgres/postgres-connection.js +207 -0
- package/dist/esm/postgres/postgres-queue-backend.d.ts +304 -0
- package/dist/esm/postgres/postgres-queue-backend.js +1701 -0
- package/dist/esm/postgres/sql-loader.d.ts +6 -0
- package/dist/esm/postgres/sql-loader.js +43 -0
- package/dist/esm/scripts/addDelayedJob-6.js +25 -57
- package/dist/esm/scripts/addJobScheduler-11.js +11 -18
- package/dist/esm/scripts/addParentJob-6.js +20 -49
- package/dist/esm/scripts/addPrioritizedJob-9.js +25 -57
- package/dist/esm/scripts/addStandardJob-9.js +31 -61
- package/dist/esm/scripts/changePriority-7.js +15 -16
- package/dist/esm/scripts/cleanJobsInSet-3.js +9 -13
- package/dist/esm/scripts/drain-5.js +9 -13
- package/dist/esm/scripts/getCountsPerPriority-4.js +1 -13
- package/dist/esm/scripts/index.d.ts +0 -3
- package/dist/esm/scripts/index.js +0 -3
- package/dist/esm/scripts/moveJobFromActiveToWait-9.js +8 -12
- package/dist/esm/scripts/moveJobsToWait-8.js +8 -12
- package/dist/esm/scripts/moveStalledJobsToWait-9.js +24 -28
- package/dist/esm/scripts/moveToActive-11.js +22 -23
- package/dist/esm/scripts/moveToDelayed-12.js +22 -23
- package/dist/esm/scripts/moveToFinished-14.js +30 -32
- package/dist/esm/scripts/obliterate-2.js +15 -13
- package/dist/esm/scripts/pause-7.js +31 -5
- package/dist/esm/scripts/promote-9.js +10 -14
- package/dist/esm/scripts/removeChildDependency-1.js +9 -13
- package/dist/esm/scripts/removeJob-2.js +9 -13
- package/dist/esm/scripts/removeUnprocessedChildren-2.js +9 -13
- package/dist/esm/scripts/reprocessJob-8.js +8 -12
- package/dist/esm/scripts/retryJob-11.js +3 -23
- package/dist/esm/scripts/updateJobScheduler-12.js +9 -22
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/dist/esm/types/job-options.d.ts +11 -45
- package/dist/esm/types/job-scheduler-template-options.d.ts +1 -1
- package/dist/esm/types/job-type.d.ts +1 -1
- package/dist/esm/utils/create-backend.d.ts +26 -0
- package/dist/esm/utils/create-backend.js +75 -0
- package/dist/esm/utils/index.d.ts +3 -8
- package/dist/esm/utils/index.js +2 -23
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/package.json +48 -21
- package/dist/cjs/classes/repeat.js +0 -203
- package/dist/cjs/commands/addRepeatableJob-2.lua +0 -84
- package/dist/cjs/commands/includes/getTargetQueueList.lua +0 -22
- package/dist/cjs/commands/removeRepeatable-3.lua +0 -58
- package/dist/cjs/commands/updateRepeatableJobMillis-1.lua +0 -28
- package/dist/cjs/scripts/addRepeatableJob-2.js +0 -237
- package/dist/cjs/scripts/removeRepeatable-3.js +0 -62
- package/dist/cjs/scripts/updateRepeatableJobMillis-1.js +0 -32
- package/dist/cjs/utils/create-scripts.js +0 -21
- package/dist/esm/classes/repeat.d.ts +0 -25
- package/dist/esm/classes/repeat.js +0 -198
- package/dist/esm/commands/addRepeatableJob-2.lua +0 -84
- package/dist/esm/commands/includes/getTargetQueueList.lua +0 -22
- package/dist/esm/commands/removeRepeatable-3.lua +0 -58
- package/dist/esm/commands/updateRepeatableJobMillis-1.lua +0 -28
- package/dist/esm/interfaces/repeatable-job.d.ts +0 -10
- package/dist/esm/scripts/addRepeatableJob-2.d.ts +0 -5
- package/dist/esm/scripts/addRepeatableJob-2.js +0 -234
- package/dist/esm/scripts/removeRepeatable-3.d.ts +0 -5
- package/dist/esm/scripts/removeRepeatable-3.js +0 -59
- package/dist/esm/scripts/updateRepeatableJobMillis-1.d.ts +0 -5
- package/dist/esm/scripts/updateRepeatableJobMillis-1.js +0 -29
- package/dist/esm/utils/create-scripts.d.ts +0 -3
- package/dist/esm/utils/create-scripts.js +0 -17
- /package/dist/cjs/interfaces/{repeatable-job.js → queue-backend.js} +0 -0
- /package/dist/esm/interfaces/{repeatable-job.js → queue-backend.js} +0 -0
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
<br/>
|
|
5
5
|
<br/>
|
|
6
6
|
<p>
|
|
7
|
-
The fastest, most reliable, Redis-based distributed queue for Node.js, Python, Rust, and more. <br/>
|
|
7
|
+
The fastest, most reliable, Redis-based distributed queue for Node.js, Python, Elixir, Rust, PHP, and more. <br/>
|
|
8
8
|
Carefully written for rock solid stability and atomicity.
|
|
9
9
|
</p>
|
|
10
10
|
Read the <a href="https://docs.bullmq.io">documentation</a>
|
|
@@ -44,7 +44,7 @@ BullMQ is available natively in multiple languages:
|
|
|
44
44
|
|
|
45
45
|
- **Node.js / Bun** — This repository (`npm install bullmq`)
|
|
46
46
|
- **Python** — [`python/`](./python) directory (`pip install bullmq`)
|
|
47
|
-
- **Rust** — [`rust/`](./rust) directory (`cargo add bullmq`)
|
|
47
|
+
- **Rust** — [`rust/`](./rust) directory (`cargo add bullmq-official --rename bullmq`)
|
|
48
48
|
- **Elixir** — [`elixir/`](./elixir) directory (`{:bullmq, "~> x.x"}`)
|
|
49
49
|
- **PHP** — [`php/`](./php) directory
|
|
50
50
|
|
|
@@ -186,7 +186,13 @@ class BunRedisAdapter extends events_1.EventEmitter {
|
|
|
186
186
|
// Connection lifecycle
|
|
187
187
|
// ---------------------------------------------------------------
|
|
188
188
|
async connect() {
|
|
189
|
-
|
|
189
|
+
const replaceRaw = this.hasConnected && (this.closed || !this.raw.connected);
|
|
190
|
+
if (this.reconnectTimer) {
|
|
191
|
+
clearTimeout(this.reconnectTimer);
|
|
192
|
+
this.reconnectTimer = null;
|
|
193
|
+
}
|
|
194
|
+
this.reconnecting = false;
|
|
195
|
+
if (this.raw.connected && !replaceRaw) {
|
|
190
196
|
this.hasConnected = true;
|
|
191
197
|
this.closed = false;
|
|
192
198
|
this.closing = false;
|
|
@@ -199,7 +205,7 @@ class BunRedisAdapter extends events_1.EventEmitter {
|
|
|
199
205
|
this.statusOverride = undefined;
|
|
200
206
|
// If the raw client was previously closed, Bun doesn't support
|
|
201
207
|
// reconnecting on the same instance. Create a fresh raw client.
|
|
202
|
-
if (
|
|
208
|
+
if (replaceRaw) {
|
|
203
209
|
const BunRedisClient = this.raw
|
|
204
210
|
.constructor;
|
|
205
211
|
this.raw = new BunRedisClient(this.raw.url);
|
|
@@ -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
|
|
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: {} },
|
|
18
|
+
constructor(opts = { connection: {} }, backendFactory = (0, create_backend_1.getDefaultBackendFactory)()) {
|
|
21
19
|
super();
|
|
22
20
|
this.opts = opts;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
-
(
|
|
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.
|
|
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
|
-
|
|
95
|
-
|
|
96
|
-
|
|
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
|
-
|
|
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 =
|
|
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
|
-
|
|
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(
|
|
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
|
-
*
|
|
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
|
-
|
|
170
|
-
|
|
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
|
|
180
|
-
const
|
|
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({
|
|
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,
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
244
|
+
entries,
|
|
254
245
|
nodes: node.children,
|
|
255
246
|
parent: {
|
|
256
247
|
parentOpts: {
|
|
257
248
|
id: parentId,
|
|
258
|
-
queue:
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
288
|
-
const parentOpts =
|
|
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
|
-
|
|
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(
|
|
304
|
-
const queue = this.queueFromNode(node,
|
|
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(
|
|
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
|
-
|
|
338
|
-
|
|
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(
|
|
352
|
+
getChildren(childrenKeys, depth, maxChildren) {
|
|
341
353
|
const getChild = (key) => {
|
|
342
|
-
const
|
|
343
|
-
return this.getNode(
|
|
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
|
|
359
|
-
* @
|
|
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,
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
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:
|
|
373
|
-
toKey: (type) =>
|
|
381
|
+
keys: backend.keys,
|
|
382
|
+
toKey: (type) => backend.toKey(type),
|
|
374
383
|
opts: { prefix, connection: {} },
|
|
375
|
-
qualifiedName:
|
|
376
|
-
|
|
377
|
-
|
|
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.
|
|
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.
|
|
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("./
|
|
28
|
+
tslib_1.__exportStar(require("./redis-queue-backend"), exports);
|
|
30
29
|
tslib_1.__exportStar(require("./worker"), exports);
|