bullmq 6.3.11 → 6.3.13
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/queue-getters.js +3 -1
- package/dist/cjs/classes/queue.js +2 -1
- package/dist/cjs/classes/redis-connection.js +1 -1
- package/dist/cjs/classes/redis-queue-backend.js +1 -1
- package/dist/cjs/commands/includes/moveChildBackToParentDependencies.lua +20 -0
- package/dist/cjs/commands/moveJobsToWait-8.lua +3 -0
- package/dist/cjs/commands/reprocessJob-7.lua +2 -14
- package/dist/cjs/postgres/sql-loader.js +27 -41
- package/dist/cjs/postgres/sql-scripts.js +110 -0
- package/dist/cjs/scripts/moveJobsToWait-8.js +21 -0
- package/dist/cjs/scripts/reprocessJob-7.js +20 -13
- package/dist/cjs/tsconfig-cjs.tsbuildinfo +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/classes/queue-getters.d.ts +3 -1
- package/dist/esm/classes/queue-getters.js +3 -1
- package/dist/esm/classes/queue.d.ts +2 -1
- package/dist/esm/classes/queue.js +2 -1
- package/dist/esm/classes/redis-connection.d.ts +1 -1
- package/dist/esm/classes/redis-connection.js +1 -1
- package/dist/esm/classes/redis-queue-backend.d.ts +1 -1
- package/dist/esm/classes/redis-queue-backend.js +1 -1
- package/dist/esm/commands/includes/moveChildBackToParentDependencies.lua +20 -0
- package/dist/esm/commands/moveJobsToWait-8.lua +3 -0
- package/dist/esm/commands/reprocessJob-7.lua +2 -14
- 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/scripts/moveJobsToWait-8.js +21 -0
- package/dist/esm/scripts/reprocessJob-7.js +20 -13
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/package.json +10 -9
- 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
|
@@ -172,7 +172,7 @@ export class RedisConnection extends EventEmitter {
|
|
|
172
172
|
}
|
|
173
173
|
/**
|
|
174
174
|
* Waits for a redis client to be ready.
|
|
175
|
-
* @param
|
|
175
|
+
* @param client - Redis client to wait for.
|
|
176
176
|
*/
|
|
177
177
|
static async waitUntilReady(client) {
|
|
178
178
|
if (client.status === 'ready') {
|
|
@@ -353,8 +353,8 @@ export declare class RedisQueueBackend extends EventEmitter implements IQueueBac
|
|
|
353
353
|
* This script is used when a job has been manually rate limited and needs
|
|
354
354
|
* to be moved back to wait from active status.
|
|
355
355
|
*
|
|
356
|
-
* @param client - Redis client
|
|
357
356
|
* @param jobId - Job id
|
|
357
|
+
* @param token - Lock token of the job. Defaults to '0'.
|
|
358
358
|
* @returns
|
|
359
359
|
*/
|
|
360
360
|
moveJobFromActiveToWait(jobId: string, token?: string): Promise<any>;
|
|
@@ -1435,8 +1435,8 @@ export class RedisQueueBackend extends EventEmitter {
|
|
|
1435
1435
|
* This script is used when a job has been manually rate limited and needs
|
|
1436
1436
|
* to be moved back to wait from active status.
|
|
1437
1437
|
*
|
|
1438
|
-
* @param client - Redis client
|
|
1439
1438
|
* @param jobId - Job id
|
|
1439
|
+
* @param token - Lock token of the job. Defaults to '0'.
|
|
1440
1440
|
* @returns
|
|
1441
1441
|
*/
|
|
1442
1442
|
async moveJobFromActiveToWait(jobId, token = '0') {
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
--[[
|
|
2
|
+
Function to move a retried child back to its parent's dependencies.
|
|
3
|
+
This does not move a parent that has already left waiting-children back to that state.
|
|
4
|
+
]]
|
|
5
|
+
local function moveChildBackToParentDependencies(jobKey, prevState)
|
|
6
|
+
local parentKey = rcall("HGET", jobKey, "parentKey")
|
|
7
|
+
|
|
8
|
+
if parentKey and rcall("EXISTS", parentKey) == 1 then
|
|
9
|
+
if prevState == "failed" then
|
|
10
|
+
if rcall("ZREM", parentKey .. ":unsuccessful", jobKey) == 1 or
|
|
11
|
+
rcall("HDEL", parentKey .. ":failed", jobKey) == 1 then
|
|
12
|
+
rcall("SADD", parentKey .. ":dependencies", jobKey)
|
|
13
|
+
end
|
|
14
|
+
else
|
|
15
|
+
if rcall("HDEL", parentKey .. ":processed", jobKey) == 1 then
|
|
16
|
+
rcall("SADD", parentKey .. ":dependencies", jobKey)
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -31,6 +31,7 @@ local rcall = redis.call;
|
|
|
31
31
|
--- @include "includes/batches"
|
|
32
32
|
--- @include "includes/getOrSetMaxEvents"
|
|
33
33
|
--- @include "includes/isQueuePausedOrMaxed"
|
|
34
|
+
--- @include "includes/moveChildBackToParentDependencies"
|
|
34
35
|
|
|
35
36
|
local metaKey = KEYS[6]
|
|
36
37
|
local isPausedOrMaxed = isQueuePausedOrMaxed(metaKey, KEYS[7])
|
|
@@ -42,11 +43,13 @@ if (#jobs > 0) then
|
|
|
42
43
|
for i, key in ipairs(jobs) do
|
|
43
44
|
local jobKey = KEYS[1] .. key
|
|
44
45
|
rcall("HDEL", jobKey, "finishedOn", "processedOn", "failedReason")
|
|
46
|
+
moveChildBackToParentDependencies(jobKey, ARGV[3])
|
|
45
47
|
end
|
|
46
48
|
elseif ARGV[3] == "completed" then
|
|
47
49
|
for i, key in ipairs(jobs) do
|
|
48
50
|
local jobKey = KEYS[1] .. key
|
|
49
51
|
rcall("HDEL", jobKey, "finishedOn", "processedOn", "returnvalue")
|
|
52
|
+
moveChildBackToParentDependencies(jobKey, ARGV[3])
|
|
50
53
|
end
|
|
51
54
|
end
|
|
52
55
|
|
|
@@ -28,6 +28,7 @@ local rcall = redis.call;
|
|
|
28
28
|
--- @include "includes/addJobInTargetList"
|
|
29
29
|
--- @include "includes/getOrSetMaxEvents"
|
|
30
30
|
--- @include "includes/isQueuePausedOrMaxed"
|
|
31
|
+
--- @include "includes/moveChildBackToParentDependencies"
|
|
31
32
|
|
|
32
33
|
local jobKey = KEYS[1]
|
|
33
34
|
if rcall("EXISTS", jobKey) == 1 then
|
|
@@ -48,20 +49,7 @@ if rcall("EXISTS", jobKey) == 1 then
|
|
|
48
49
|
local isPausedOrMaxed = isQueuePausedOrMaxed(KEYS[5], KEYS[6])
|
|
49
50
|
addJobInTargetList(KEYS[4], KEYS[7], ARGV[2], isPausedOrMaxed, jobId)
|
|
50
51
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
if parentKey and rcall("EXISTS", parentKey) == 1 then
|
|
54
|
-
if ARGV[4] == "failed" then
|
|
55
|
-
if rcall("ZREM", parentKey .. ":unsuccessful", jobKey) == 1 or
|
|
56
|
-
rcall("HDEL", parentKey .. ":failed", jobKey) == 1 then
|
|
57
|
-
rcall("SADD", parentKey .. ":dependencies", jobKey)
|
|
58
|
-
end
|
|
59
|
-
else
|
|
60
|
-
if rcall("HDEL", parentKey .. ":processed", jobKey) == 1 then
|
|
61
|
-
rcall("SADD", parentKey .. ":dependencies", jobKey)
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
end
|
|
52
|
+
moveChildBackToParentDependencies(jobKey, ARGV[4])
|
|
65
53
|
|
|
66
54
|
local maxEvents = getOrSetMaxEvents(KEYS[5])
|
|
67
55
|
-- Emit waiting event
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
export declare function loadMigrationSql(file: string): string;
|
|
2
2
|
/**
|
|
3
3
|
* Loads a runtime command's SQL by name (without the `.sql` extension), cached
|
|
4
|
-
* after the first
|
|
4
|
+
* after the first lookup. Runtime queries contain NO schema/namespace
|
|
5
|
+
* references — the connection's `search_path` selects the schema — so they are
|
|
6
|
+
* portable verbatim to the Python/Elixir/PHP/Rust ports (mirroring how the
|
|
7
|
+
* Redis backend's `.lua` scripts never hardcode the key prefix).
|
|
8
|
+
*
|
|
9
|
+
* @param name - Command name, e.g. `add_job`.
|
|
5
10
|
*/
|
|
6
11
|
export declare function loadCommandSql(name: string): string;
|
|
@@ -1,62 +1,48 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { dirname, join } from 'path';
|
|
3
|
-
import { fileURLToPath } from 'url';
|
|
4
|
-
function getDirname() {
|
|
5
|
-
if (typeof __dirname !== 'undefined' && __dirname) {
|
|
6
|
-
return __dirname;
|
|
7
|
-
}
|
|
8
|
-
const stack = new Error().stack || '';
|
|
9
|
-
for (const line of stack.split('\n')) {
|
|
10
|
-
const match = line.match(/(file:\/\/\/[^\s)]+)/);
|
|
11
|
-
if (match) {
|
|
12
|
-
try {
|
|
13
|
-
return dirname(fileURLToPath(match[1]));
|
|
14
|
-
}
|
|
15
|
-
catch (_a) {
|
|
16
|
-
// continue searching
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
throw new Error('Could not determine sql-loader directory path');
|
|
21
|
-
}
|
|
22
|
-
const currentDir = getDirname();
|
|
1
|
+
import { SQL_COMMANDS, SQL_MIGRATIONS } from './sql-scripts';
|
|
23
2
|
/**
|
|
24
|
-
* Loads a migration's SQL
|
|
25
|
-
*
|
|
3
|
+
* Loads a migration's SQL — the portable source of truth shared with the
|
|
4
|
+
* Elixir/Python ports. Results are cached after the first lookup.
|
|
26
5
|
*
|
|
27
|
-
* The
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
* `search_path` selects the schema — so they are portable verbatim to the
|
|
38
|
-
* Python/Elixir/PHP/Rust ports (mirroring how the Redis backend's `.lua`
|
|
39
|
-
* scripts never hardcode the key prefix).
|
|
6
|
+
* The SQL is inlined into the published JavaScript at build time (see
|
|
7
|
+
* scripts/generateSqlScripts.js), exactly like the Redis backend's `.lua`
|
|
8
|
+
* scripts, so no filesystem access is needed at runtime. This keeps the
|
|
9
|
+
* PostgreSQL backend usable from single-file bundles (bun build --compile,
|
|
10
|
+
* esbuild --bundle, pkg, Node SEA, deno compile) where the `.sql` files are
|
|
11
|
+
* not shipped alongside the code:
|
|
12
|
+
*
|
|
13
|
+
* @see https://github.com/taskforcesh/bullmq/issues/4603
|
|
14
|
+
*
|
|
15
|
+
* @param file - Migration filename, e.g. `0001_schema.sql`.
|
|
40
16
|
*/
|
|
41
|
-
const COMMANDS_DIR = join(currentDir, 'commands');
|
|
42
17
|
const migrationCache = new Map();
|
|
43
18
|
const commandCache = new Map();
|
|
44
19
|
export function loadMigrationSql(file) {
|
|
45
20
|
let sql = migrationCache.get(file);
|
|
46
21
|
if (sql === undefined) {
|
|
47
|
-
sql =
|
|
22
|
+
sql = SQL_MIGRATIONS[file];
|
|
23
|
+
if (sql === undefined) {
|
|
24
|
+
throw new Error(`Could not find migration SQL for '${file}'`);
|
|
25
|
+
}
|
|
48
26
|
migrationCache.set(file, sql);
|
|
49
27
|
}
|
|
50
28
|
return sql;
|
|
51
29
|
}
|
|
52
30
|
/**
|
|
53
31
|
* Loads a runtime command's SQL by name (without the `.sql` extension), cached
|
|
54
|
-
* after the first
|
|
32
|
+
* after the first lookup. Runtime queries contain NO schema/namespace
|
|
33
|
+
* references — the connection's `search_path` selects the schema — so they are
|
|
34
|
+
* portable verbatim to the Python/Elixir/PHP/Rust ports (mirroring how the
|
|
35
|
+
* Redis backend's `.lua` scripts never hardcode the key prefix).
|
|
36
|
+
*
|
|
37
|
+
* @param name - Command name, e.g. `add_job`.
|
|
55
38
|
*/
|
|
56
39
|
export function loadCommandSql(name) {
|
|
57
40
|
let sql = commandCache.get(name);
|
|
58
41
|
if (sql === undefined) {
|
|
59
|
-
sql =
|
|
42
|
+
sql = SQL_COMMANDS[`${name}.sql`];
|
|
43
|
+
if (sql === undefined) {
|
|
44
|
+
throw new Error(`Could not find command SQL for '${name}'`);
|
|
45
|
+
}
|
|
60
46
|
commandCache.set(name, sql);
|
|
61
47
|
}
|
|
62
48
|
return sql;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime query SQL, keyed by command name (filename without the .sql
|
|
3
|
+
* extension), matching the keys used by loadCommandSql().
|
|
4
|
+
*/
|
|
5
|
+
export declare const SQL_COMMANDS: Record<string, string>;
|
|
6
|
+
/**
|
|
7
|
+
* Schema migration SQL, keyed by filename (e.g. '0001_schema.sql'), matching
|
|
8
|
+
* the keys used by loadMigrationSql().
|
|
9
|
+
*/
|
|
10
|
+
export declare const SQL_MIGRATIONS: Record<string, string>;
|