bullmq 6.0.2 → 6.0.4
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/postgres/commands/add_flow.sql +1 -1
- package/dist/cjs/postgres/commands/add_job.sql +1 -1
- package/dist/cjs/postgres/commands/add_job_scheduler.sql +1 -1
- package/dist/cjs/postgres/commands/add_jobs_bulk.sql +1 -1
- package/dist/cjs/postgres/commands/add_log.sql +2 -2
- package/dist/cjs/postgres/commands/change_delay.sql +1 -1
- package/dist/cjs/postgres/commands/change_priority.sql +1 -1
- package/dist/cjs/postgres/commands/clean.sql +1 -1
- package/dist/cjs/postgres/commands/clear_logs.sql +2 -2
- package/dist/cjs/postgres/commands/collect_metrics.sql +1 -1
- package/dist/cjs/postgres/commands/delete_deduplication_key.sql +1 -1
- package/dist/cjs/postgres/commands/drain.sql +1 -1
- package/dist/cjs/postgres/commands/extend_lock.sql +1 -1
- package/dist/cjs/postgres/commands/extend_locks.sql +1 -1
- package/dist/cjs/postgres/commands/get_counts.sql +2 -2
- package/dist/cjs/postgres/commands/get_counts_per_priority.sql +1 -1
- package/dist/cjs/postgres/commands/get_deduplication_job_id.sql +1 -1
- package/dist/cjs/postgres/commands/get_dependencies.sql +1 -1
- package/dist/cjs/postgres/commands/get_dependencies_page.sql +2 -2
- package/dist/cjs/postgres/commands/get_dependency_counts.sql +1 -1
- package/dist/cjs/postgres/commands/get_ignored_children_failures.sql +1 -1
- package/dist/cjs/postgres/commands/get_job_data.sql +1 -1
- package/dist/cjs/postgres/commands/get_job_logs_asc.sql +1 -1
- package/dist/cjs/postgres/commands/get_job_logs_count.sql +1 -1
- package/dist/cjs/postgres/commands/get_job_logs_desc.sql +1 -1
- package/dist/cjs/postgres/commands/get_job_scheduler.sql +1 -1
- package/dist/cjs/postgres/commands/get_job_schedulers_count.sql +1 -1
- package/dist/cjs/postgres/commands/get_job_schedulers_range.sql +1 -1
- package/dist/cjs/postgres/commands/get_metrics.sql +2 -2
- package/dist/cjs/postgres/commands/get_processed_children_values.sql +1 -1
- package/dist/cjs/postgres/commands/get_queue_meta.sql +1 -1
- package/dist/cjs/postgres/commands/get_queue_meta_field.sql +1 -1
- package/dist/cjs/postgres/commands/get_queue_meta_fields.sql +1 -1
- package/dist/cjs/postgres/commands/get_range.sql +1 -1
- package/dist/cjs/postgres/commands/get_rate_limit_ttl.sql +1 -1
- package/dist/cjs/postgres/commands/get_state.sql +1 -1
- package/dist/cjs/postgres/commands/has_queue_meta_field.sql +1 -1
- package/dist/cjs/postgres/commands/has_waiting_job.sql +2 -2
- package/dist/cjs/postgres/commands/is_finished.sql +1 -1
- package/dist/cjs/postgres/commands/is_job_in_state.sql +2 -2
- package/dist/cjs/postgres/commands/is_job_in_wait.sql +2 -2
- package/dist/cjs/postgres/commands/is_job_prioritized.sql +1 -1
- package/dist/cjs/postgres/commands/is_job_scheduler.sql +1 -1
- package/dist/cjs/postgres/commands/is_maxed.sql +2 -2
- package/dist/cjs/postgres/commands/move_active_to_wait.sql +1 -1
- package/dist/cjs/postgres/commands/move_stalled_jobs_to_wait.sql +1 -1
- package/dist/cjs/postgres/commands/move_to_active.sql +1 -1
- package/dist/cjs/postgres/commands/move_to_completed.sql +1 -1
- package/dist/cjs/postgres/commands/move_to_completed_fetch.sql +1 -1
- package/dist/cjs/postgres/commands/move_to_delayed.sql +1 -1
- package/dist/cjs/postgres/commands/move_to_failed.sql +1 -1
- package/dist/cjs/postgres/commands/move_to_failed_fetch.sql +1 -1
- package/dist/cjs/postgres/commands/move_to_waiting_children.sql +1 -1
- package/dist/cjs/postgres/commands/next_delay.sql +1 -1
- package/dist/cjs/postgres/commands/next_signal.sql +1 -1
- package/dist/cjs/postgres/commands/obliterate.sql +1 -1
- package/dist/cjs/postgres/commands/paginate_dependencies.sql +4 -4
- package/dist/cjs/postgres/commands/pause.sql +1 -1
- package/dist/cjs/postgres/commands/promote.sql +1 -1
- package/dist/cjs/postgres/commands/promote_jobs.sql +1 -1
- package/dist/cjs/postgres/commands/publish_event.sql +1 -1
- package/dist/cjs/postgres/commands/read_events.sql +1 -1
- package/dist/cjs/postgres/commands/read_events_max.sql +1 -1
- package/dist/cjs/postgres/commands/remove.sql +1 -1
- package/dist/cjs/postgres/commands/remove_child_dependency.sql +1 -1
- package/dist/cjs/postgres/commands/remove_deduplication_key.sql +1 -1
- package/dist/cjs/postgres/commands/remove_job_scheduler.sql +1 -1
- package/dist/cjs/postgres/commands/remove_queue_meta_fields.sql +1 -1
- package/dist/cjs/postgres/commands/remove_rate_limit.sql +1 -1
- package/dist/cjs/postgres/commands/remove_unprocessed_children.sql +1 -1
- package/dist/cjs/postgres/commands/reprocess_job.sql +1 -1
- package/dist/cjs/postgres/commands/retry_job.sql +1 -1
- package/dist/cjs/postgres/commands/retry_jobs.sql +1 -1
- package/dist/cjs/postgres/commands/set_queue_meta.sql +1 -1
- package/dist/cjs/postgres/commands/set_rate_limit.sql +1 -1
- package/dist/cjs/postgres/commands/trim_logs.sql +1 -1
- package/dist/cjs/postgres/commands/update_data.sql +1 -1
- package/dist/cjs/postgres/commands/update_job_scheduler.sql +1 -1
- package/dist/cjs/postgres/commands/update_progress.sql +1 -1
- package/dist/cjs/postgres/migrations/0001_schema.sql +47 -47
- package/dist/cjs/postgres/migrations/0002_functions.sql +409 -409
- package/dist/cjs/postgres/migrator.js +6 -3
- package/dist/cjs/postgres/postgres-queue-backend.js +5 -5
- package/dist/cjs/tsconfig-cjs.tsbuildinfo +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/postgres/commands/add_flow.sql +1 -1
- package/dist/esm/postgres/commands/add_job.sql +1 -1
- package/dist/esm/postgres/commands/add_job_scheduler.sql +1 -1
- package/dist/esm/postgres/commands/add_jobs_bulk.sql +1 -1
- package/dist/esm/postgres/commands/add_log.sql +2 -2
- package/dist/esm/postgres/commands/change_delay.sql +1 -1
- package/dist/esm/postgres/commands/change_priority.sql +1 -1
- package/dist/esm/postgres/commands/clean.sql +1 -1
- package/dist/esm/postgres/commands/clear_logs.sql +2 -2
- package/dist/esm/postgres/commands/collect_metrics.sql +1 -1
- package/dist/esm/postgres/commands/delete_deduplication_key.sql +1 -1
- package/dist/esm/postgres/commands/drain.sql +1 -1
- package/dist/esm/postgres/commands/extend_lock.sql +1 -1
- package/dist/esm/postgres/commands/extend_locks.sql +1 -1
- package/dist/esm/postgres/commands/get_counts.sql +2 -2
- package/dist/esm/postgres/commands/get_counts_per_priority.sql +1 -1
- package/dist/esm/postgres/commands/get_deduplication_job_id.sql +1 -1
- package/dist/esm/postgres/commands/get_dependencies.sql +1 -1
- package/dist/esm/postgres/commands/get_dependencies_page.sql +2 -2
- package/dist/esm/postgres/commands/get_dependency_counts.sql +1 -1
- package/dist/esm/postgres/commands/get_ignored_children_failures.sql +1 -1
- package/dist/esm/postgres/commands/get_job_data.sql +1 -1
- package/dist/esm/postgres/commands/get_job_logs_asc.sql +1 -1
- package/dist/esm/postgres/commands/get_job_logs_count.sql +1 -1
- package/dist/esm/postgres/commands/get_job_logs_desc.sql +1 -1
- package/dist/esm/postgres/commands/get_job_scheduler.sql +1 -1
- package/dist/esm/postgres/commands/get_job_schedulers_count.sql +1 -1
- package/dist/esm/postgres/commands/get_job_schedulers_range.sql +1 -1
- package/dist/esm/postgres/commands/get_metrics.sql +2 -2
- package/dist/esm/postgres/commands/get_processed_children_values.sql +1 -1
- package/dist/esm/postgres/commands/get_queue_meta.sql +1 -1
- package/dist/esm/postgres/commands/get_queue_meta_field.sql +1 -1
- package/dist/esm/postgres/commands/get_queue_meta_fields.sql +1 -1
- package/dist/esm/postgres/commands/get_range.sql +1 -1
- package/dist/esm/postgres/commands/get_rate_limit_ttl.sql +1 -1
- package/dist/esm/postgres/commands/get_state.sql +1 -1
- package/dist/esm/postgres/commands/has_queue_meta_field.sql +1 -1
- package/dist/esm/postgres/commands/has_waiting_job.sql +2 -2
- package/dist/esm/postgres/commands/is_finished.sql +1 -1
- package/dist/esm/postgres/commands/is_job_in_state.sql +2 -2
- package/dist/esm/postgres/commands/is_job_in_wait.sql +2 -2
- package/dist/esm/postgres/commands/is_job_prioritized.sql +1 -1
- package/dist/esm/postgres/commands/is_job_scheduler.sql +1 -1
- package/dist/esm/postgres/commands/is_maxed.sql +2 -2
- package/dist/esm/postgres/commands/move_active_to_wait.sql +1 -1
- package/dist/esm/postgres/commands/move_stalled_jobs_to_wait.sql +1 -1
- package/dist/esm/postgres/commands/move_to_active.sql +1 -1
- package/dist/esm/postgres/commands/move_to_completed.sql +1 -1
- package/dist/esm/postgres/commands/move_to_completed_fetch.sql +1 -1
- package/dist/esm/postgres/commands/move_to_delayed.sql +1 -1
- package/dist/esm/postgres/commands/move_to_failed.sql +1 -1
- package/dist/esm/postgres/commands/move_to_failed_fetch.sql +1 -1
- package/dist/esm/postgres/commands/move_to_waiting_children.sql +1 -1
- package/dist/esm/postgres/commands/next_delay.sql +1 -1
- package/dist/esm/postgres/commands/next_signal.sql +1 -1
- package/dist/esm/postgres/commands/obliterate.sql +1 -1
- package/dist/esm/postgres/commands/paginate_dependencies.sql +4 -4
- package/dist/esm/postgres/commands/pause.sql +1 -1
- package/dist/esm/postgres/commands/promote.sql +1 -1
- package/dist/esm/postgres/commands/promote_jobs.sql +1 -1
- package/dist/esm/postgres/commands/publish_event.sql +1 -1
- package/dist/esm/postgres/commands/read_events.sql +1 -1
- package/dist/esm/postgres/commands/read_events_max.sql +1 -1
- package/dist/esm/postgres/commands/remove.sql +1 -1
- package/dist/esm/postgres/commands/remove_child_dependency.sql +1 -1
- package/dist/esm/postgres/commands/remove_deduplication_key.sql +1 -1
- package/dist/esm/postgres/commands/remove_job_scheduler.sql +1 -1
- package/dist/esm/postgres/commands/remove_queue_meta_fields.sql +1 -1
- package/dist/esm/postgres/commands/remove_rate_limit.sql +1 -1
- package/dist/esm/postgres/commands/remove_unprocessed_children.sql +1 -1
- package/dist/esm/postgres/commands/reprocess_job.sql +1 -1
- package/dist/esm/postgres/commands/retry_job.sql +1 -1
- package/dist/esm/postgres/commands/retry_jobs.sql +1 -1
- package/dist/esm/postgres/commands/set_queue_meta.sql +1 -1
- package/dist/esm/postgres/commands/set_rate_limit.sql +1 -1
- package/dist/esm/postgres/commands/trim_logs.sql +1 -1
- package/dist/esm/postgres/commands/update_data.sql +1 -1
- package/dist/esm/postgres/commands/update_job_scheduler.sql +1 -1
- package/dist/esm/postgres/commands/update_progress.sql +1 -1
- package/dist/esm/postgres/migrations/0001_schema.sql +47 -47
- package/dist/esm/postgres/migrations/0002_functions.sql +409 -409
- package/dist/esm/postgres/migrations/index.d.ts +1 -1
- package/dist/esm/postgres/migrator.js +6 -3
- package/dist/esm/postgres/postgres-queue-backend.d.ts +4 -4
- package/dist/esm/postgres/postgres-queue-backend.js +5 -5
- 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 +6 -6
|
@@ -3,4 +3,4 @@
|
|
|
3
3
|
-- $3 next_millis, $4 template_data (jsonb), $5 template_opts (jsonb),
|
|
4
4
|
-- $6 opts (jsonb), $7 delayed_opts (jsonb), $8 now, $9 producer_id.
|
|
5
5
|
SELECT job_id, delay
|
|
6
|
-
FROM
|
|
6
|
+
FROM add_job_scheduler($1, $2, $3, $4, $5, $6, $7, $8, $9);
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
-- Fast set-based bulk insert of INDEPENDENT jobs (no parents, no dedup).
|
|
2
2
|
-- Param: $1 queue, $2 entries (jsonb array). Returns the job ids in input order.
|
|
3
|
-
SELECT id FROM
|
|
3
|
+
SELECT id FROM add_jobs_bulk($1, $2::jsonb) AS t(id);
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
-- Params: $1 queue, $2 job_id, $3 row.
|
|
3
3
|
-- The unqualified table name resolves in the configured BullMQ schema via
|
|
4
4
|
-- search_path (default schema: bullmq).
|
|
5
|
-
INSERT INTO
|
|
5
|
+
INSERT INTO job_log (queue, job_id, idx, row)
|
|
6
6
|
VALUES (
|
|
7
7
|
$1, $2,
|
|
8
8
|
COALESCE(
|
|
9
|
-
(SELECT MAX(idx) + 1 FROM
|
|
9
|
+
(SELECT MAX(idx) + 1 FROM job_log WHERE queue = $1 AND job_id = $2),
|
|
10
10
|
0
|
|
11
11
|
),
|
|
12
12
|
$3
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
-- Clear a job's logs, keeping the latest $3 entries (NULL/0 → remove all).
|
|
2
2
|
-- Params: $1 queue, $2 job_id, $3 keepLogs.
|
|
3
|
-
DELETE FROM
|
|
3
|
+
DELETE FROM job_log
|
|
4
4
|
WHERE queue = $1 AND job_id = $2
|
|
5
5
|
AND idx < COALESCE(
|
|
6
|
-
(SELECT MAX(idx) FROM
|
|
6
|
+
(SELECT MAX(idx) FROM job_log WHERE queue = $1 AND job_id = $2)
|
|
7
7
|
- $3 + 1,
|
|
8
8
|
idx + 1
|
|
9
9
|
);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
-- Record one finished job into the queue/kind metrics (per-minute deltas).
|
|
2
2
|
-- Params: $1 queue, $2 kind ('completed' | 'failed'), $3 maxDataPoints,
|
|
3
3
|
-- $4 finish timestamp (epoch ms).
|
|
4
|
-
SELECT
|
|
4
|
+
SELECT collect_metrics($1, $2, $3, $4);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
-- Unconditionally remove a deduplication key (Queue.removeDeduplicationKey /
|
|
2
2
|
-- the deprecated removeDebounceKey). Params: $1 queue, $2 dedup_id. Returns the
|
|
3
3
|
-- removed key (0 or 1 row).
|
|
4
|
-
DELETE FROM
|
|
4
|
+
DELETE FROM dedup
|
|
5
5
|
WHERE queue = $1 AND dedup_id = $2
|
|
6
6
|
RETURNING dedup_id;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
-- Remove waiting (and optionally delayed) jobs. Params: $1 queue, $2 delayed.
|
|
2
|
-
SELECT
|
|
2
|
+
SELECT drain($1, $2);
|
|
@@ -8,6 +8,6 @@ SELECT
|
|
|
8
8
|
COUNT(*) FILTER (WHERE state = 'waiting' AND priority = 0) AS waiting,
|
|
9
9
|
COUNT(*) FILTER (WHERE state = 'waiting' AND priority > 0) AS prioritized,
|
|
10
10
|
COUNT(*) FILTER (WHERE state = 'waiting-children') AS "waiting-children",
|
|
11
|
-
(SELECT value FROM
|
|
12
|
-
FROM
|
|
11
|
+
(SELECT value FROM meta WHERE queue = $1 AND field = 'paused') AS paused
|
|
12
|
+
FROM job
|
|
13
13
|
WHERE queue = $1;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
-- The current "winner" job id for a deduplication key, or none when absent or
|
|
2
2
|
-- expired. Params: $1 queue, $2 dedup_id, $3 now (ms).
|
|
3
3
|
SELECT job_id
|
|
4
|
-
FROM
|
|
4
|
+
FROM dedup
|
|
5
5
|
WHERE queue = $1
|
|
6
6
|
AND dedup_id = $2
|
|
7
7
|
AND (expire_at_ms IS NULL OR expire_at_ms > $3);
|
|
@@ -3,6 +3,6 @@
|
|
|
3
3
|
-- processed → processed (value = return value), pending → unprocessed,
|
|
4
4
|
-- ignored → ignored (value = reason), failed → failed.
|
|
5
5
|
SELECT status::text AS status, child_key, value
|
|
6
|
-
FROM
|
|
6
|
+
FROM job_dependency
|
|
7
7
|
WHERE parent_queue = $1 AND parent_id = $2
|
|
8
8
|
ORDER BY child_id;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
-- One page of a parent's child dependencies in a single status category.
|
|
2
2
|
-- Params: $1 parent_queue, $2 parent_id, $3 status, $4 offset, $5 count.
|
|
3
3
|
SELECT child_key, value
|
|
4
|
-
FROM
|
|
5
|
-
WHERE parent_queue = $1 AND parent_id = $2 AND status = $3::
|
|
4
|
+
FROM job_dependency
|
|
5
|
+
WHERE parent_queue = $1 AND parent_id = $2 AND status = $3::dep_status
|
|
6
6
|
ORDER BY child_id
|
|
7
7
|
OFFSET $4 LIMIT $5;
|
|
@@ -5,5 +5,5 @@ SELECT
|
|
|
5
5
|
COUNT(*) FILTER (WHERE status = 'pending') AS unprocessed,
|
|
6
6
|
COUNT(*) FILTER (WHERE status = 'ignored') AS ignored,
|
|
7
7
|
COUNT(*) FILTER (WHERE status = 'failed') AS failed
|
|
8
|
-
FROM
|
|
8
|
+
FROM job_dependency
|
|
9
9
|
WHERE parent_queue = $1 AND parent_id = $2;
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
-- is stored as a JSON scalar string, so `#>> '{}'` extracts the raw text
|
|
3
3
|
-- (mirrors the Redis `<jobId>:failed` hash). Params: $1 parent_queue, $2 parent_id.
|
|
4
4
|
SELECT child_key, COALESCE(value #>> '{}', value::text) AS reason
|
|
5
|
-
FROM
|
|
5
|
+
FROM job_dependency
|
|
6
6
|
WHERE parent_queue = $1 AND parent_id = $2 AND status = 'ignored'
|
|
7
7
|
ORDER BY child_id;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
-- A job's full row. Params: $1 queue, $2 id.
|
|
2
|
-
SELECT * FROM
|
|
2
|
+
SELECT * FROM job WHERE queue = $1 AND id = $2;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
-- Total number of log lines for a job. Params: $1 queue, $2 job_id.
|
|
2
|
-
SELECT COUNT(*) AS count FROM
|
|
2
|
+
SELECT COUNT(*) AS count FROM job_log WHERE queue = $1 AND job_id = $2;
|
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
-- Params: $1 queue, $2 scheduler_id.
|
|
3
3
|
SELECT name, iteration_count, limit_count, start_date_ms, end_date_ms, tz,
|
|
4
4
|
pattern, every_ms, offset_ms, template_data, template_opts, next_run_ms
|
|
5
|
-
FROM
|
|
5
|
+
FROM scheduler
|
|
6
6
|
WHERE queue = $1 AND scheduler_id = $2;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
-- Number of registered schedulers in a queue. Param: $1 queue.
|
|
2
|
-
SELECT count(*)::int AS count FROM
|
|
2
|
+
SELECT count(*)::int AS count FROM scheduler WHERE queue = $1;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
-- Fetch a page of schedulers ordered by next-run time. Params: $1 queue,
|
|
2
2
|
-- $2 asc (boolean), $3 offset, $4 count (NULL = all remaining).
|
|
3
3
|
SELECT scheduler_id, next_run_ms
|
|
4
|
-
FROM
|
|
4
|
+
FROM scheduler
|
|
5
5
|
WHERE queue = $1
|
|
6
6
|
ORDER BY CASE WHEN $2 THEN next_run_ms END ASC,
|
|
7
7
|
CASE WHEN NOT $2 THEN next_run_ms END DESC,
|
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
-- (index 0 is the newest point; a negative end means "to the oldest").
|
|
4
4
|
-- Params: $1 queue, $2 kind ('completed' | 'failed'), $3 start, $4 end.
|
|
5
5
|
SELECT
|
|
6
|
-
COALESCE((SELECT count FROM
|
|
6
|
+
COALESCE((SELECT count FROM metrics
|
|
7
7
|
WHERE queue = $1 AND kind = $2), 0)::bigint AS total,
|
|
8
8
|
COALESCE((
|
|
9
9
|
SELECT CASE
|
|
10
10
|
WHEN $4 < 0 THEN data[($3 + 1) : ]
|
|
11
11
|
ELSE data[($3 + 1) : ($4 + 1)]
|
|
12
12
|
END
|
|
13
|
-
FROM
|
|
13
|
+
FROM metrics WHERE queue = $1 AND kind = $2
|
|
14
14
|
), ARRAY[]::bigint[]) AS data;
|
|
@@ -3,6 +3,6 @@
|
|
|
3
3
|
-- Redis `<jobId>:processed` hash of stringified values). Params: $1 parent_queue,
|
|
4
4
|
-- $2 parent_id.
|
|
5
5
|
SELECT child_key, value::text AS value
|
|
6
|
-
FROM
|
|
6
|
+
FROM job_dependency
|
|
7
7
|
WHERE parent_queue = $1 AND parent_id = $2 AND status = 'processed'
|
|
8
8
|
ORDER BY child_id;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
-- The full queue metadata hash. Param: $1 queue.
|
|
2
|
-
SELECT field, value FROM
|
|
2
|
+
SELECT field, value FROM meta WHERE queue = $1;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
-- A single queue metadata field's value. Params: $1 queue, $2 field.
|
|
2
|
-
SELECT value FROM
|
|
2
|
+
SELECT value FROM meta WHERE queue = $1 AND field = $2;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
-- A job's state and priority. Params: $1 queue, $2 id.
|
|
2
|
-
SELECT state, priority FROM
|
|
2
|
+
SELECT state, priority FROM job WHERE queue = $1 AND id = $2;
|
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
-- established (mirrors the atomicity of Redis's blocking pop). Param: $1 queue.
|
|
4
4
|
SELECT
|
|
5
5
|
EXISTS(
|
|
6
|
-
SELECT 1 FROM
|
|
6
|
+
SELECT 1 FROM job WHERE queue = $1 AND state = 'waiting'
|
|
7
7
|
)
|
|
8
8
|
AND NOT EXISTS(
|
|
9
|
-
SELECT 1 FROM
|
|
9
|
+
SELECT 1 FROM meta
|
|
10
10
|
WHERE queue = $1 AND field = 'paused' AND value = '1'
|
|
11
11
|
) AS present;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
-- Whether a job is currently in the given state. Params: $1 queue, $2 id,
|
|
2
2
|
-- $3 state.
|
|
3
3
|
SELECT EXISTS(
|
|
4
|
-
SELECT 1 FROM
|
|
5
|
-
WHERE queue = $1 AND id = $2 AND state = $3::
|
|
4
|
+
SELECT 1 FROM job
|
|
5
|
+
WHERE queue = $1 AND id = $2 AND state = $3::job_state
|
|
6
6
|
) AS present;
|
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
-- when the queue is paused, and to the wait list otherwise. $3 selects which
|
|
4
4
|
-- list to test (true = paused, false = wait). Params: $1 queue, $2 id, $3 paused.
|
|
5
5
|
SELECT EXISTS(
|
|
6
|
-
SELECT 1 FROM
|
|
6
|
+
SELECT 1 FROM job j
|
|
7
7
|
WHERE j.queue = $1 AND j.id = $2
|
|
8
8
|
AND j.state = 'waiting' AND j.priority = 0
|
|
9
9
|
AND (
|
|
10
10
|
EXISTS(
|
|
11
|
-
SELECT 1 FROM
|
|
11
|
+
SELECT 1 FROM meta m
|
|
12
12
|
WHERE m.queue = $1 AND m.field = 'paused' AND m.value = '1'
|
|
13
13
|
)
|
|
14
14
|
) = $3
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
-- when no concurrency limit is configured.
|
|
4
4
|
-- Params: $1 queue.
|
|
5
5
|
SELECT COALESCE(
|
|
6
|
-
(SELECT count(*) FROM
|
|
7
|
-
>= (SELECT value::integer FROM
|
|
6
|
+
(SELECT count(*) FROM job WHERE queue = $1 AND state = 'active')
|
|
7
|
+
>= (SELECT value::integer FROM meta
|
|
8
8
|
WHERE queue = $1 AND field = 'concurrency'),
|
|
9
9
|
false
|
|
10
10
|
) AS maxed;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
-- Move an active job back to wait (Job.moveToWait / dynamic rate limit).
|
|
2
2
|
-- Params: $1 queue, $2 id, $3 token ('0' bypasses the lock check), $4 now_ms.
|
|
3
3
|
-- Returns the limiter window ms (>=0), or -1 when the job no longer exists.
|
|
4
|
-
SELECT
|
|
4
|
+
SELECT move_active_to_wait($1, $2, $3, $4) AS n;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
-- Two-phase stalled-job recovery (mark on one pass, reclaim on the next);
|
|
2
2
|
-- returns the reclaimed ids. Params: $1 queue, $2 max_stalled_count,
|
|
3
3
|
-- $3 now_ms, $4 max_check_time_ms (stalledInterval).
|
|
4
|
-
SELECT id FROM
|
|
4
|
+
SELECT id FROM move_stalled_jobs_to_wait($1, $2, $3, $4) AS t(id);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
-- Claim the next ready job for a worker (0 or 1 rows), honouring the limiter.
|
|
2
2
|
-- Params: $1 queue, $2 token, $3 lock_ms, $4 now_ms, $5 worker name,
|
|
3
3
|
-- $6 limiter max (worker option, NULL if none), $7 limiter duration ms.
|
|
4
|
-
SELECT * FROM
|
|
4
|
+
SELECT * FROM move_to_active($1, $2, $3, $4, $5, $6, $7);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
-- Finish an active job successfully; returns the finished-at timestamp.
|
|
2
2
|
-- Params: $1 queue, $2 id, $3 token, $4 return_value (jsonb), $5 finished_on,
|
|
3
3
|
-- $6 remove_all, $7 keep_age (s), $8 keep_count.
|
|
4
|
-
SELECT
|
|
4
|
+
SELECT move_to_completed($1, $2, $3, $4::jsonb, $5, $6, $7, $8) AS finished_on;
|
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
-- $6 remove_all, $7 keep_age (s), $8 keep_count,
|
|
6
6
|
-- $9 lock_ms, $10 now_ms, $11 worker name,
|
|
7
7
|
-- $12 limiter max (worker option, NULL if none), $13 limiter duration ms.
|
|
8
|
-
SELECT * FROM
|
|
8
|
+
SELECT * FROM move_to_completed_fetch(
|
|
9
9
|
$1, $2, $3, $4::jsonb, $5, $6, $7, $8, $9, $10, $11, $12, $13);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
-- Re-queue an active job to the delayed state (retry-with-delay / manual delay).
|
|
2
2
|
-- Params: $1 queue, $2 id, $3 token, $4 process_at, $5 delay,
|
|
3
3
|
-- $6 skip_attempt, $7 failed_reason, $8 stacktrace (jsonb).
|
|
4
|
-
SELECT
|
|
4
|
+
SELECT move_to_delayed($1, $2, $3, $4, $5, $6, $7, $8::jsonb) AS n;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
-- Mark an active job failed; returns the finished-at timestamp.
|
|
2
2
|
-- Params: $1 queue, $2 id, $3 token, $4 failed_reason, $5 stacktrace (jsonb),
|
|
3
3
|
-- $6 finished_on, $7 remove_all, $8 keep_age (s), $9 keep_count.
|
|
4
|
-
SELECT
|
|
4
|
+
SELECT move_to_failed($1, $2, $3, $4, $5::jsonb, $6, $7, $8, $9) AS finished_on;
|
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
-- $6 finished_on, $7 remove_all, $8 keep_age (s), $9 keep_count,
|
|
6
6
|
-- $10 lock_ms, $11 now_ms, $12 worker name,
|
|
7
7
|
-- $13 limiter max (worker option, NULL if none), $14 limiter duration ms.
|
|
8
|
-
SELECT * FROM
|
|
8
|
+
SELECT * FROM move_to_failed_fetch(
|
|
9
9
|
$1, $2, $3, $4, $5::jsonb, $6, $7, $8, $9, $10, $11, $12, $13, $14);
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
-- The timestamp of the next delayed job, or NULL if there are none.
|
|
2
|
-
SELECT
|
|
2
|
+
SELECT next_delay($1) AS next_delay;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
-- The worker "no job" signal: effective rate-limit ttl + next delayed-job time.
|
|
2
2
|
-- Params: $1 queue, $2 limiter max (worker option, NULL if none), $3 now_ms.
|
|
3
|
-
SELECT rate_limit_ttl, next_delay FROM
|
|
3
|
+
SELECT rate_limit_ttl, next_delay FROM next_signal($1, $2, $3);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
-- Obliterate a queue: delete up to $2 jobs; returns -1 (not paused), -2 (active
|
|
2
2
|
-- jobs without force), 1 (more to delete), or 0 (done). Params: $1 queue,
|
|
3
3
|
-- $2 count, $3 force.
|
|
4
|
-
SELECT
|
|
4
|
+
SELECT obliterate($1, $2, $3) AS cursor;
|
|
@@ -4,16 +4,16 @@
|
|
|
4
4
|
-- (NULL = no limit). `total` is the full number of matching dependencies
|
|
5
5
|
-- (COUNT(*) OVER(), computed before the slice). `dep_value` is the stored
|
|
6
6
|
-- result for processed children. The remaining columns are the child
|
|
7
|
-
-- `
|
|
7
|
+
-- `job` row consumed by rowToJobJson.
|
|
8
8
|
SELECT
|
|
9
9
|
d.child_key,
|
|
10
10
|
d.value AS dep_value,
|
|
11
11
|
COUNT(*) OVER() AS total,
|
|
12
12
|
j.*
|
|
13
|
-
FROM
|
|
14
|
-
LEFT JOIN
|
|
13
|
+
FROM job_dependency d
|
|
14
|
+
LEFT JOIN job j
|
|
15
15
|
ON j.queue = d.child_queue AND j.id = d.child_id
|
|
16
|
-
WHERE d.parent_queue = $1 AND d.parent_id = $2 AND d.status = $3::
|
|
16
|
+
WHERE d.parent_queue = $1 AND d.parent_id = $2 AND d.status = $3::dep_status
|
|
17
17
|
ORDER BY d.child_key
|
|
18
18
|
OFFSET $4
|
|
19
19
|
LIMIT $5;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
-- Pause/resume the queue. Params: $1 queue, $2 paused.
|
|
2
|
-
SELECT
|
|
2
|
+
SELECT pause($1, $2);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
-- Break a child's dependency link to its parent. Params: $1 queue, $2 job_id,
|
|
2
2
|
-- $3 parent_key, $4 now. Returns 0 (removed) or 1 (no relationship); raises on
|
|
3
3
|
-- missing job (-1) / missing parent (-5).
|
|
4
|
-
SELECT
|
|
4
|
+
SELECT remove_child_dependency($1, $2, $3, $4) AS n;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
-- job-instance Job.removeDeduplicationKey, where Redis GET returns nil for an
|
|
4
4
|
-- expired key). Params: $1 queue, $2 dedup_id, $3 job_id, $4 now (ms). Returns
|
|
5
5
|
-- the removed key (0 or 1 row).
|
|
6
|
-
DELETE FROM
|
|
6
|
+
DELETE FROM dedup
|
|
7
7
|
WHERE queue = $1 AND dedup_id = $2 AND job_id = $3
|
|
8
8
|
AND (expire_at_ms IS NULL OR expire_at_ms > $4)
|
|
9
9
|
RETURNING dedup_id;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
-- Remove queue metadata fields. Params: $1 queue, $2 fields (text[]).
|
|
2
|
-
DELETE FROM
|
|
2
|
+
DELETE FROM meta WHERE queue = $1 AND field = ANY($2::text[]);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
-- Re-queue a finished job (failed/completed) back to wait. Params: $1 queue,
|
|
2
2
|
-- $2 id, $3 state, $4 lifo, $5 reset_attempts_made, $6 reset_attempts_started.
|
|
3
3
|
-- Returns 1 ok, -1 missing, -3 not in the expected state.
|
|
4
|
-
SELECT
|
|
4
|
+
SELECT reprocess_job($1, $2, $3, $4, $5, $6) AS code;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
-- Re-queue an active job back to waiting immediately (retry now).
|
|
2
2
|
-- Params: $1 queue, $2 id, $3 token, $4 lifo, $5 failed_reason, $6 stacktrace (jsonb).
|
|
3
|
-
SELECT
|
|
3
|
+
SELECT retry_job($1, $2, $3, $4, $5, $6::jsonb) AS n;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
-- Upsert queue metadata fields. Params: $1 queue, $2 fields (text[]), $3 values (text[]).
|
|
2
|
-
INSERT INTO
|
|
2
|
+
INSERT INTO meta (queue, field, value)
|
|
3
3
|
SELECT $1, f, v FROM unnest($2::text[], $3::text[]) AS t(f, v)
|
|
4
4
|
ON CONFLICT (queue, field) DO UPDATE SET value = EXCLUDED.value;
|