bullmq 6.3.10 → 6.3.12
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/dist/cjs/classes/worker.js +108 -21
- package/dist/cjs/postgres/sql-loader.js +27 -41
- package/dist/cjs/postgres/sql-scripts.js +110 -0
- package/dist/cjs/tsconfig-cjs.tsbuildinfo +1 -1
- package/dist/cjs/utils/index.js +29 -0
- package/dist/cjs/version.js +1 -1
- package/dist/esm/classes/worker.d.ts +2 -1
- package/dist/esm/classes/worker.js +109 -22
- package/dist/esm/interfaces/telemetry.d.ts +15 -0
- package/dist/esm/postgres/sql-loader.d.ts +6 -1
- package/dist/esm/postgres/sql-loader.js +27 -41
- package/dist/esm/postgres/sql-scripts.d.ts +10 -0
- package/dist/esm/postgres/sql-scripts.js +107 -0
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/dist/esm/utils/index.d.ts +24 -0
- package/dist/esm/utils/index.js +28 -0
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/package.json +11 -10
- package/dist/cjs/postgres/commands/add_flow.sql +0 -3
- package/dist/cjs/postgres/commands/add_job.sql +0 -5
- package/dist/cjs/postgres/commands/add_job_scheduler.sql +0 -6
- package/dist/cjs/postgres/commands/add_jobs_bulk.sql +0 -3
- package/dist/cjs/postgres/commands/add_log.sql +0 -14
- package/dist/cjs/postgres/commands/change_delay.sql +0 -3
- package/dist/cjs/postgres/commands/change_priority.sql +0 -3
- package/dist/cjs/postgres/commands/clean.sql +0 -3
- package/dist/cjs/postgres/commands/clear_logs.sql +0 -9
- package/dist/cjs/postgres/commands/collect_metrics.sql +0 -4
- package/dist/cjs/postgres/commands/delete_deduplication_key.sql +0 -6
- package/dist/cjs/postgres/commands/drain.sql +0 -2
- package/dist/cjs/postgres/commands/extend_lock.sql +0 -3
- package/dist/cjs/postgres/commands/extend_locks.sql +0 -25
- package/dist/cjs/postgres/commands/get_client_list.sql +0 -11
- package/dist/cjs/postgres/commands/get_counts.sql +0 -13
- package/dist/cjs/postgres/commands/get_counts_per_priority.sql +0 -14
- package/dist/cjs/postgres/commands/get_deduplication_job_id.sql +0 -7
- package/dist/cjs/postgres/commands/get_dependencies.sql +0 -8
- package/dist/cjs/postgres/commands/get_dependencies_page.sql +0 -7
- package/dist/cjs/postgres/commands/get_dependency_counts.sql +0 -9
- package/dist/cjs/postgres/commands/get_ignored_children_failures.sql +0 -7
- package/dist/cjs/postgres/commands/get_job_data.sql +0 -2
- package/dist/cjs/postgres/commands/get_job_logs_asc.sql +0 -6
- package/dist/cjs/postgres/commands/get_job_logs_count.sql +0 -2
- package/dist/cjs/postgres/commands/get_job_logs_desc.sql +0 -6
- package/dist/cjs/postgres/commands/get_job_scheduler.sql +0 -6
- package/dist/cjs/postgres/commands/get_job_schedulers_count.sql +0 -2
- package/dist/cjs/postgres/commands/get_job_schedulers_range.sql +0 -10
- package/dist/cjs/postgres/commands/get_metrics.sql +0 -14
- package/dist/cjs/postgres/commands/get_processed_children_values.sql +0 -8
- package/dist/cjs/postgres/commands/get_queue_meta.sql +0 -2
- package/dist/cjs/postgres/commands/get_queue_meta_field.sql +0 -2
- package/dist/cjs/postgres/commands/get_queue_meta_fields.sql +0 -3
- package/dist/cjs/postgres/commands/get_range.sql +0 -3
- package/dist/cjs/postgres/commands/get_rate_limit_ttl.sql +0 -3
- package/dist/cjs/postgres/commands/get_state.sql +0 -2
- package/dist/cjs/postgres/commands/has_queue_meta_field.sql +0 -4
- package/dist/cjs/postgres/commands/has_waiting_job.sql +0 -11
- package/dist/cjs/postgres/commands/is_finished.sql +0 -4
- package/dist/cjs/postgres/commands/is_job_in_state.sql +0 -6
- package/dist/cjs/postgres/commands/is_job_in_wait.sql +0 -15
- package/dist/cjs/postgres/commands/is_job_prioritized.sql +0 -6
- package/dist/cjs/postgres/commands/is_job_scheduler.sql +0 -4
- package/dist/cjs/postgres/commands/is_maxed.sql +0 -10
- package/dist/cjs/postgres/commands/listen_events.sql +0 -3
- package/dist/cjs/postgres/commands/listen_jobs.sql +0 -4
- package/dist/cjs/postgres/commands/move_active_to_wait.sql +0 -4
- package/dist/cjs/postgres/commands/move_stalled_jobs_to_wait.sql +0 -4
- package/dist/cjs/postgres/commands/move_to_active.sql +0 -4
- package/dist/cjs/postgres/commands/move_to_completed.sql +0 -4
- package/dist/cjs/postgres/commands/move_to_completed_fetch.sql +0 -9
- package/dist/cjs/postgres/commands/move_to_delayed.sql +0 -4
- package/dist/cjs/postgres/commands/move_to_failed.sql +0 -4
- package/dist/cjs/postgres/commands/move_to_failed_fetch.sql +0 -9
- package/dist/cjs/postgres/commands/move_to_waiting_children.sql +0 -3
- package/dist/cjs/postgres/commands/next_delay.sql +0 -2
- package/dist/cjs/postgres/commands/next_signal.sql +0 -3
- package/dist/cjs/postgres/commands/obliterate.sql +0 -4
- package/dist/cjs/postgres/commands/paginate_dependencies.sql +0 -19
- package/dist/cjs/postgres/commands/pause.sql +0 -2
- package/dist/cjs/postgres/commands/promote.sql +0 -3
- package/dist/cjs/postgres/commands/promote_jobs.sql +0 -3
- package/dist/cjs/postgres/commands/publish_event.sql +0 -3
- package/dist/cjs/postgres/commands/read_events.sql +0 -6
- package/dist/cjs/postgres/commands/read_events_max.sql +0 -3
- package/dist/cjs/postgres/commands/remove.sql +0 -3
- package/dist/cjs/postgres/commands/remove_child_dependency.sql +0 -4
- package/dist/cjs/postgres/commands/remove_deduplication_key.sql +0 -9
- package/dist/cjs/postgres/commands/remove_job_scheduler.sql +0 -3
- package/dist/cjs/postgres/commands/remove_queue_meta_fields.sql +0 -2
- package/dist/cjs/postgres/commands/remove_rate_limit.sql +0 -6
- package/dist/cjs/postgres/commands/remove_unprocessed_children.sql +0 -3
- package/dist/cjs/postgres/commands/reprocess_job.sql +0 -4
- package/dist/cjs/postgres/commands/retry_job.sql +0 -3
- package/dist/cjs/postgres/commands/retry_jobs.sql +0 -3
- package/dist/cjs/postgres/commands/set_queue_meta.sql +0 -4
- package/dist/cjs/postgres/commands/set_rate_limit.sql +0 -3
- package/dist/cjs/postgres/commands/trim_logs.sql +0 -3
- package/dist/cjs/postgres/commands/update_data.sql +0 -3
- package/dist/cjs/postgres/commands/update_job_scheduler.sql +0 -5
- package/dist/cjs/postgres/commands/update_progress.sql +0 -3
- package/dist/cjs/postgres/migrations/0001_schema.sql +0 -348
- package/dist/cjs/postgres/migrations/0002_functions.sql +0 -3473
- package/dist/cjs/postgres/migrations/0003_dedup_stale_key.sql +0 -147
- package/dist/esm/postgres/commands/add_flow.sql +0 -3
- package/dist/esm/postgres/commands/add_job.sql +0 -5
- package/dist/esm/postgres/commands/add_job_scheduler.sql +0 -6
- package/dist/esm/postgres/commands/add_jobs_bulk.sql +0 -3
- package/dist/esm/postgres/commands/add_log.sql +0 -14
- package/dist/esm/postgres/commands/change_delay.sql +0 -3
- package/dist/esm/postgres/commands/change_priority.sql +0 -3
- package/dist/esm/postgres/commands/clean.sql +0 -3
- package/dist/esm/postgres/commands/clear_logs.sql +0 -9
- package/dist/esm/postgres/commands/collect_metrics.sql +0 -4
- package/dist/esm/postgres/commands/delete_deduplication_key.sql +0 -6
- package/dist/esm/postgres/commands/drain.sql +0 -2
- package/dist/esm/postgres/commands/extend_lock.sql +0 -3
- package/dist/esm/postgres/commands/extend_locks.sql +0 -25
- package/dist/esm/postgres/commands/get_client_list.sql +0 -11
- package/dist/esm/postgres/commands/get_counts.sql +0 -13
- package/dist/esm/postgres/commands/get_counts_per_priority.sql +0 -14
- package/dist/esm/postgres/commands/get_deduplication_job_id.sql +0 -7
- package/dist/esm/postgres/commands/get_dependencies.sql +0 -8
- package/dist/esm/postgres/commands/get_dependencies_page.sql +0 -7
- package/dist/esm/postgres/commands/get_dependency_counts.sql +0 -9
- package/dist/esm/postgres/commands/get_ignored_children_failures.sql +0 -7
- package/dist/esm/postgres/commands/get_job_data.sql +0 -2
- package/dist/esm/postgres/commands/get_job_logs_asc.sql +0 -6
- package/dist/esm/postgres/commands/get_job_logs_count.sql +0 -2
- package/dist/esm/postgres/commands/get_job_logs_desc.sql +0 -6
- package/dist/esm/postgres/commands/get_job_scheduler.sql +0 -6
- package/dist/esm/postgres/commands/get_job_schedulers_count.sql +0 -2
- package/dist/esm/postgres/commands/get_job_schedulers_range.sql +0 -10
- package/dist/esm/postgres/commands/get_metrics.sql +0 -14
- package/dist/esm/postgres/commands/get_processed_children_values.sql +0 -8
- package/dist/esm/postgres/commands/get_queue_meta.sql +0 -2
- package/dist/esm/postgres/commands/get_queue_meta_field.sql +0 -2
- package/dist/esm/postgres/commands/get_queue_meta_fields.sql +0 -3
- package/dist/esm/postgres/commands/get_range.sql +0 -3
- package/dist/esm/postgres/commands/get_rate_limit_ttl.sql +0 -3
- package/dist/esm/postgres/commands/get_state.sql +0 -2
- package/dist/esm/postgres/commands/has_queue_meta_field.sql +0 -4
- package/dist/esm/postgres/commands/has_waiting_job.sql +0 -11
- package/dist/esm/postgres/commands/is_finished.sql +0 -4
- package/dist/esm/postgres/commands/is_job_in_state.sql +0 -6
- package/dist/esm/postgres/commands/is_job_in_wait.sql +0 -15
- package/dist/esm/postgres/commands/is_job_prioritized.sql +0 -6
- package/dist/esm/postgres/commands/is_job_scheduler.sql +0 -4
- package/dist/esm/postgres/commands/is_maxed.sql +0 -10
- package/dist/esm/postgres/commands/listen_events.sql +0 -3
- package/dist/esm/postgres/commands/listen_jobs.sql +0 -4
- package/dist/esm/postgres/commands/move_active_to_wait.sql +0 -4
- package/dist/esm/postgres/commands/move_stalled_jobs_to_wait.sql +0 -4
- package/dist/esm/postgres/commands/move_to_active.sql +0 -4
- package/dist/esm/postgres/commands/move_to_completed.sql +0 -4
- package/dist/esm/postgres/commands/move_to_completed_fetch.sql +0 -9
- package/dist/esm/postgres/commands/move_to_delayed.sql +0 -4
- package/dist/esm/postgres/commands/move_to_failed.sql +0 -4
- package/dist/esm/postgres/commands/move_to_failed_fetch.sql +0 -9
- package/dist/esm/postgres/commands/move_to_waiting_children.sql +0 -3
- package/dist/esm/postgres/commands/next_delay.sql +0 -2
- package/dist/esm/postgres/commands/next_signal.sql +0 -3
- package/dist/esm/postgres/commands/obliterate.sql +0 -4
- package/dist/esm/postgres/commands/paginate_dependencies.sql +0 -19
- package/dist/esm/postgres/commands/pause.sql +0 -2
- package/dist/esm/postgres/commands/promote.sql +0 -3
- package/dist/esm/postgres/commands/promote_jobs.sql +0 -3
- package/dist/esm/postgres/commands/publish_event.sql +0 -3
- package/dist/esm/postgres/commands/read_events.sql +0 -6
- package/dist/esm/postgres/commands/read_events_max.sql +0 -3
- package/dist/esm/postgres/commands/remove.sql +0 -3
- package/dist/esm/postgres/commands/remove_child_dependency.sql +0 -4
- package/dist/esm/postgres/commands/remove_deduplication_key.sql +0 -9
- package/dist/esm/postgres/commands/remove_job_scheduler.sql +0 -3
- package/dist/esm/postgres/commands/remove_queue_meta_fields.sql +0 -2
- package/dist/esm/postgres/commands/remove_rate_limit.sql +0 -6
- package/dist/esm/postgres/commands/remove_unprocessed_children.sql +0 -3
- package/dist/esm/postgres/commands/reprocess_job.sql +0 -4
- package/dist/esm/postgres/commands/retry_job.sql +0 -3
- package/dist/esm/postgres/commands/retry_jobs.sql +0 -3
- package/dist/esm/postgres/commands/set_queue_meta.sql +0 -4
- package/dist/esm/postgres/commands/set_rate_limit.sql +0 -3
- package/dist/esm/postgres/commands/trim_logs.sql +0 -3
- package/dist/esm/postgres/commands/update_data.sql +0 -3
- package/dist/esm/postgres/commands/update_job_scheduler.sql +0 -5
- package/dist/esm/postgres/commands/update_progress.sql +0 -3
- package/dist/esm/postgres/migrations/0001_schema.sql +0 -348
- package/dist/esm/postgres/migrations/0002_functions.sql +0 -3473
- package/dist/esm/postgres/migrations/0003_dedup_stale_key.sql +0 -147
|
@@ -46,7 +46,11 @@ class Worker extends queue_base_1.QueueBase {
|
|
|
46
46
|
this.drained = false;
|
|
47
47
|
this.limitUntil = 0;
|
|
48
48
|
this.processorAcceptsSignal = false;
|
|
49
|
-
|
|
49
|
+
// Bumped whenever the currently running stalled-checker loop should be
|
|
50
|
+
// abandoned (e.g. by `pause()`). The loop compares its own captured value
|
|
51
|
+
// against the live counter on every iteration and exits as soon as they
|
|
52
|
+
// diverge, without anyone having to await it.
|
|
53
|
+
this.stalledCheckerGeneration = 0;
|
|
50
54
|
this.waiting = null;
|
|
51
55
|
this.running = false;
|
|
52
56
|
this.mainLoopRunning = null;
|
|
@@ -671,6 +675,12 @@ class Worker extends queue_base_1.QueueBase {
|
|
|
671
675
|
* Pauses the processing of this queue only for this worker.
|
|
672
676
|
*/
|
|
673
677
|
async pause(doNotWaitActive) {
|
|
678
|
+
// Kept in the caller's active context (not detached): a correctly
|
|
679
|
+
// implemented AsyncLocalStorage-based context manager isolates concurrent
|
|
680
|
+
// async chains, so a background stalled-checker tick (which detaches its
|
|
681
|
+
// own context; see `stalledChecker()`) cannot overwrite this span's
|
|
682
|
+
// context. Staying attached lets applications correlate `pause` with the
|
|
683
|
+
// request or operation that initiated it.
|
|
674
684
|
await this.trace(enums_1.SpanKind.INTERNAL, 'pause', this.name, async (span) => {
|
|
675
685
|
var _a;
|
|
676
686
|
span === null || span === void 0 ? void 0 : span.setAttributes({
|
|
@@ -683,6 +693,14 @@ class Worker extends queue_base_1.QueueBase {
|
|
|
683
693
|
if (!doNotWaitActive) {
|
|
684
694
|
await this.whenCurrentJobsFinished();
|
|
685
695
|
}
|
|
696
|
+
// Invalidate the currently running stalled-checker loop and cancel
|
|
697
|
+
// its pending timer. This is intentionally fire-and-forget: the
|
|
698
|
+
// loop may be in the middle of an in-flight Redis call (which, on
|
|
699
|
+
// a connection error, retries with its own delay), so awaiting it
|
|
700
|
+
// here could block `pause()` for an unbounded amount of time. The
|
|
701
|
+
// loop itself checks the generation on every iteration and will
|
|
702
|
+
// exit on its own as soon as it next has a chance to.
|
|
703
|
+
this.stalledCheckerGeneration++;
|
|
686
704
|
(_a = this.stalledCheckStopper) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
687
705
|
this.emit('paused');
|
|
688
706
|
}
|
|
@@ -695,6 +713,10 @@ class Worker extends queue_base_1.QueueBase {
|
|
|
695
713
|
async resume() {
|
|
696
714
|
try {
|
|
697
715
|
if (!this.running || this.paused) {
|
|
716
|
+
let restartStalledChecker = false;
|
|
717
|
+
// Kept in the caller's active context for the same reason as
|
|
718
|
+
// `pause()`: only the background stalled-checker loop needs to
|
|
719
|
+
// detach its own context, so it cannot leak into this span.
|
|
698
720
|
await this.trace(enums_1.SpanKind.INTERNAL, 'resume', this.name, async (span) => {
|
|
699
721
|
span === null || span === void 0 ? void 0 : span.setAttributes({
|
|
700
722
|
[enums_1.TelemetryAttributes.WorkerId]: this.id,
|
|
@@ -709,10 +731,15 @@ class Worker extends queue_base_1.QueueBase {
|
|
|
709
731
|
else {
|
|
710
732
|
// Main loop is still running (pause was called with doNotWaitActive=true).
|
|
711
733
|
// Restart the stalled checker since pause() stopped it.
|
|
712
|
-
|
|
734
|
+
restartStalledChecker = true;
|
|
713
735
|
}
|
|
714
736
|
this.emit('resumed');
|
|
715
737
|
});
|
|
738
|
+
// Started outside of the trace above so that the stalled checker loop
|
|
739
|
+
// does not inherit the (already ended) `resume` span as its parent.
|
|
740
|
+
if (restartStalledChecker) {
|
|
741
|
+
await this.startStalledCheckTimer();
|
|
742
|
+
}
|
|
716
743
|
}
|
|
717
744
|
}
|
|
718
745
|
catch (error) {
|
|
@@ -801,28 +828,88 @@ class Worker extends queue_base_1.QueueBase {
|
|
|
801
828
|
* @see {@link https://docs.bullmq.io/patterns/manually-fetching-jobs}
|
|
802
829
|
*/
|
|
803
830
|
async startStalledCheckTimer() {
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
span === null || span === void 0 ? void 0 : span.setAttributes({
|
|
808
|
-
[enums_1.TelemetryAttributes.WorkerId]: this.id,
|
|
809
|
-
[enums_1.TelemetryAttributes.WorkerName]: this.opts.name,
|
|
810
|
-
});
|
|
811
|
-
this.stalledCheckerRunning = true;
|
|
812
|
-
this.stalledChecker()
|
|
813
|
-
.catch(err => {
|
|
814
|
-
this.emit('error', err);
|
|
815
|
-
})
|
|
816
|
-
.finally(() => {
|
|
817
|
-
this.stalledCheckerRunning = false;
|
|
818
|
-
});
|
|
819
|
-
});
|
|
820
|
-
}
|
|
831
|
+
var _a, _b;
|
|
832
|
+
if (this.opts.skipStalledCheck) {
|
|
833
|
+
return;
|
|
821
834
|
}
|
|
835
|
+
if (this.closing) {
|
|
836
|
+
return;
|
|
837
|
+
}
|
|
838
|
+
// Claim a new generation for this loop synchronously (before the first
|
|
839
|
+
// await), so that two concurrent callers (e.g. the automatic `run()`
|
|
840
|
+
// startup racing a manual `startStalledCheckTimer()` call, or `resume()`
|
|
841
|
+
// racing a not-yet-finished old loop that `pause()` just invalidated)
|
|
842
|
+
// cannot both end up owning a checker loop: only the call that captures
|
|
843
|
+
// the latest generation value proceeds past the check below.
|
|
844
|
+
const generation = ++this.stalledCheckerGeneration;
|
|
845
|
+
// Capture whatever loop (if any) is still winding down. Bumping the
|
|
846
|
+
// generation above only makes it stop at its next checkpoint; it does
|
|
847
|
+
// not cancel an in-flight `moveStalledJobsToWait` call, so we must let it
|
|
848
|
+
// fully finish before starting a new loop, otherwise both loops could run
|
|
849
|
+
// concurrently and scan for stalled jobs at the same time. This is
|
|
850
|
+
// chained below rather than awaited here in the public call path: an
|
|
851
|
+
// in-flight Redis call can be stuck behind `checkConnectionError`'s retry
|
|
852
|
+
// delay (or a slow reconnect) well after the worker has been paused, and
|
|
853
|
+
// callers such as `resume()` must return promptly instead of blocking on
|
|
854
|
+
// it, exactly like the previous "reuse the still-running checker"
|
|
855
|
+
// behavior used to.
|
|
856
|
+
const previousStalledCheckerPromise = this.stalledCheckerPromise;
|
|
857
|
+
// Wake up the previous loop's pending interval timer (if any) so it can
|
|
858
|
+
// observe the new generation and exit promptly, instead of leaving it to
|
|
859
|
+
// wait out the remainder of its `stalledInterval` wait.
|
|
860
|
+
(_a = this.stalledCheckStopper) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
861
|
+
await this.trace(enums_1.SpanKind.INTERNAL, 'startStalledCheckTimer', this.name, async (span) => {
|
|
862
|
+
span === null || span === void 0 ? void 0 : span.setAttributes({
|
|
863
|
+
[enums_1.TelemetryAttributes.WorkerId]: this.id,
|
|
864
|
+
[enums_1.TelemetryAttributes.WorkerName]: this.opts.name,
|
|
865
|
+
});
|
|
866
|
+
});
|
|
867
|
+
// The trace above is asynchronous, so the worker may have been closed, or
|
|
868
|
+
// another call may have claimed a newer generation, while it was in
|
|
869
|
+
// flight.
|
|
870
|
+
if (this.closing || generation !== this.stalledCheckerGeneration) {
|
|
871
|
+
return;
|
|
872
|
+
}
|
|
873
|
+
// Chain the new loop to start only once the previous one has fully
|
|
874
|
+
// exited (its errors are already handled by its own `.catch` below, so
|
|
875
|
+
// swallow them here), guaranteeing the two never scan concurrently -
|
|
876
|
+
// without awaiting that settlement from this public method, so
|
|
877
|
+
// `startStalledCheckTimer()`/`resume()` return promptly regardless of how
|
|
878
|
+
// long the previous loop's in-flight Redis call takes to settle.
|
|
879
|
+
this.stalledCheckerPromise = ((_b = previousStalledCheckerPromise === null || previousStalledCheckerPromise === void 0 ? void 0 : previousStalledCheckerPromise.catch(() => undefined)) !== null && _b !== void 0 ? _b : Promise.resolve())
|
|
880
|
+
.then(() => {
|
|
881
|
+
// The wait above can take a while (e.g. a connection error retry
|
|
882
|
+
// delay), during which the worker may have closed or yet another
|
|
883
|
+
// caller may have claimed a newer generation.
|
|
884
|
+
if (this.closing || generation !== this.stalledCheckerGeneration) {
|
|
885
|
+
return;
|
|
886
|
+
}
|
|
887
|
+
return (0, utils_1.withDetachedContext)(this.opts.telemetry, () => this.stalledChecker(generation));
|
|
888
|
+
})
|
|
889
|
+
.catch(err => {
|
|
890
|
+
this.emit('error', err);
|
|
891
|
+
});
|
|
822
892
|
}
|
|
823
|
-
async stalledChecker() {
|
|
824
|
-
|
|
893
|
+
async stalledChecker(generation) {
|
|
894
|
+
// The entire loop (including its recurring interval timer) is started
|
|
895
|
+
// under a detached root context by the caller above. Context managers
|
|
896
|
+
// backed by `AsyncLocalStorage` associate every continuation created
|
|
897
|
+
// inside a callback with whatever context was active when that
|
|
898
|
+
// continuation was created; detaching only the individual Redis call on
|
|
899
|
+
// each tick would still leave the long-lived `setTimeout` chain (and
|
|
900
|
+
// therefore every subsequent tick) parented to the caller's ambient span
|
|
901
|
+
// for the worker's whole lifetime, since a later no-op detached callback
|
|
902
|
+
// cannot retroactively replace a store that AsyncLocalStorage already
|
|
903
|
+
// restored to the outer (caller) context once the initial detached call
|
|
904
|
+
// returned.
|
|
905
|
+
while (!(this.closing || this.paused) &&
|
|
906
|
+
generation === this.stalledCheckerGeneration) {
|
|
825
907
|
await this.checkConnectionError(() => this.moveStalledJobsToWait());
|
|
908
|
+
if (this.closing ||
|
|
909
|
+
this.paused ||
|
|
910
|
+
generation !== this.stalledCheckerGeneration) {
|
|
911
|
+
break;
|
|
912
|
+
}
|
|
826
913
|
await new Promise(resolve => {
|
|
827
914
|
const timeout = setTimeout(resolve, this.opts.stalledInterval);
|
|
828
915
|
this.stalledCheckStopper = () => {
|
|
@@ -2,65 +2,51 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.loadMigrationSql = loadMigrationSql;
|
|
4
4
|
exports.loadCommandSql = loadCommandSql;
|
|
5
|
-
const
|
|
6
|
-
const path_1 = require("path");
|
|
7
|
-
const url_1 = require("url");
|
|
8
|
-
function getDirname() {
|
|
9
|
-
if (typeof __dirname !== 'undefined' && __dirname) {
|
|
10
|
-
return __dirname;
|
|
11
|
-
}
|
|
12
|
-
const stack = new Error().stack || '';
|
|
13
|
-
for (const line of stack.split('\n')) {
|
|
14
|
-
const match = line.match(/(file:\/\/\/[^\s)]+)/);
|
|
15
|
-
if (match) {
|
|
16
|
-
try {
|
|
17
|
-
return (0, path_1.dirname)((0, url_1.fileURLToPath)(match[1]));
|
|
18
|
-
}
|
|
19
|
-
catch (_a) {
|
|
20
|
-
// continue searching
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
throw new Error('Could not determine sql-loader directory path');
|
|
25
|
-
}
|
|
26
|
-
const currentDir = getDirname();
|
|
5
|
+
const sql_scripts_1 = require("./sql-scripts");
|
|
27
6
|
/**
|
|
28
|
-
* Loads a migration's SQL
|
|
29
|
-
*
|
|
7
|
+
* Loads a migration's SQL — the portable source of truth shared with the
|
|
8
|
+
* Elixir/Python ports. Results are cached after the first lookup.
|
|
30
9
|
*
|
|
31
|
-
* The
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
* `search_path` selects the schema — so they are portable verbatim to the
|
|
42
|
-
* Python/Elixir/PHP/Rust ports (mirroring how the Redis backend's `.lua`
|
|
43
|
-
* scripts never hardcode the key prefix).
|
|
10
|
+
* The SQL is inlined into the published JavaScript at build time (see
|
|
11
|
+
* scripts/generateSqlScripts.js), exactly like the Redis backend's `.lua`
|
|
12
|
+
* scripts, so no filesystem access is needed at runtime. This keeps the
|
|
13
|
+
* PostgreSQL backend usable from single-file bundles (bun build --compile,
|
|
14
|
+
* esbuild --bundle, pkg, Node SEA, deno compile) where the `.sql` files are
|
|
15
|
+
* not shipped alongside the code:
|
|
16
|
+
*
|
|
17
|
+
* @see https://github.com/taskforcesh/bullmq/issues/4603
|
|
18
|
+
*
|
|
19
|
+
* @param file - Migration filename, e.g. `0001_schema.sql`.
|
|
44
20
|
*/
|
|
45
|
-
const COMMANDS_DIR = (0, path_1.join)(currentDir, 'commands');
|
|
46
21
|
const migrationCache = new Map();
|
|
47
22
|
const commandCache = new Map();
|
|
48
23
|
function loadMigrationSql(file) {
|
|
49
24
|
let sql = migrationCache.get(file);
|
|
50
25
|
if (sql === undefined) {
|
|
51
|
-
sql =
|
|
26
|
+
sql = sql_scripts_1.SQL_MIGRATIONS[file];
|
|
27
|
+
if (sql === undefined) {
|
|
28
|
+
throw new Error(`Could not find migration SQL for '${file}'`);
|
|
29
|
+
}
|
|
52
30
|
migrationCache.set(file, sql);
|
|
53
31
|
}
|
|
54
32
|
return sql;
|
|
55
33
|
}
|
|
56
34
|
/**
|
|
57
35
|
* Loads a runtime command's SQL by name (without the `.sql` extension), cached
|
|
58
|
-
* after the first
|
|
36
|
+
* after the first lookup. Runtime queries contain NO schema/namespace
|
|
37
|
+
* references — the connection's `search_path` selects the schema — so they are
|
|
38
|
+
* portable verbatim to the Python/Elixir/PHP/Rust ports (mirroring how the
|
|
39
|
+
* Redis backend's `.lua` scripts never hardcode the key prefix).
|
|
40
|
+
*
|
|
41
|
+
* @param name - Command name, e.g. `add_job`.
|
|
59
42
|
*/
|
|
60
43
|
function loadCommandSql(name) {
|
|
61
44
|
let sql = commandCache.get(name);
|
|
62
45
|
if (sql === undefined) {
|
|
63
|
-
sql =
|
|
46
|
+
sql = sql_scripts_1.SQL_COMMANDS[`${name}.sql`];
|
|
47
|
+
if (sql === undefined) {
|
|
48
|
+
throw new Error(`Could not find command SQL for '${name}'`);
|
|
49
|
+
}
|
|
64
50
|
commandCache.set(name, sql);
|
|
65
51
|
}
|
|
66
52
|
return sql;
|