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
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
-- BullMQ PostgreSQL backend — deduplication stale-key recovery.
|
|
2
|
-
--
|
|
3
|
-
-- Replaces `deduplicate_job` (created in 0002_functions.sql) to fix two ways a
|
|
4
|
-
-- deduplication key could outlive the job it points at:
|
|
5
|
-
--
|
|
6
|
-
-- 1. Stale key: a key with no expiry is meant to disappear when its winner
|
|
7
|
-
-- finishes, but `clean`, `drain`, `obliterate` (and outages) delete the
|
|
8
|
-
-- job row without clearing the `dedup` row. Every later add then matched
|
|
9
|
-
-- that dead winner and was silently dropped, forever. Mirrors the Redis
|
|
10
|
-
-- `recoverStaleDeduplicationKey` include.
|
|
11
|
-
-- 2. Orphaned proto-next: replacing a *delayed* winner left behind any
|
|
12
|
-
-- `dedup_next` payload stashed while that winner was previously active,
|
|
13
|
-
-- so it got resurrected when the replacement finished.
|
|
14
|
-
--
|
|
15
|
-
-- Only the function body changes — no schema/DDL change — so the signature is
|
|
16
|
-
-- identical and older clients keep working against the updated schema.
|
|
17
|
-
|
|
18
|
-
CREATE OR REPLACE FUNCTION deduplicate_job(
|
|
19
|
-
p_queue text, p_dedup jsonb, p_job_id text, p_now bigint,
|
|
20
|
-
p_name text, p_data jsonb, p_opts jsonb
|
|
21
|
-
) RETURNS text
|
|
22
|
-
LANGUAGE plpgsql
|
|
23
|
-
SET search_path FROM CURRENT
|
|
24
|
-
AS $$
|
|
25
|
-
DECLARE
|
|
26
|
-
v_id text := p_dedup->>'id';
|
|
27
|
-
v_ttl bigint := NULLIF(p_dedup->>'ttl', '')::bigint;
|
|
28
|
-
v_extend boolean := COALESCE((p_dedup->>'extend')::boolean, false);
|
|
29
|
-
v_replace boolean := COALESCE((p_dedup->>'replace')::boolean, false);
|
|
30
|
-
v_keeplast boolean := COALESCE((p_dedup->>'keepLastIfActive')::boolean, false);
|
|
31
|
-
v_cur text;
|
|
32
|
-
v_exp bigint;
|
|
33
|
-
v_state job_state;
|
|
34
|
-
BEGIN
|
|
35
|
-
IF v_id IS NULL OR v_id = '' THEN
|
|
36
|
-
RETURN NULL;
|
|
37
|
-
END IF;
|
|
38
|
-
|
|
39
|
-
-- The current winner (only if the key is still live).
|
|
40
|
-
SELECT job_id, expire_at_ms INTO v_cur, v_exp
|
|
41
|
-
FROM dedup WHERE queue = p_queue AND dedup_id = v_id;
|
|
42
|
-
IF v_cur IS NULL OR (v_exp IS NOT NULL AND v_exp <= p_now) THEN
|
|
43
|
-
v_cur := NULL;
|
|
44
|
-
ELSIF v_exp IS NULL AND NOT EXISTS (
|
|
45
|
-
SELECT 1 FROM job WHERE queue = p_queue AND id = v_cur
|
|
46
|
-
) THEN
|
|
47
|
-
-- Stale key recovery (mirrors recoverStaleDeduplicationKey): a key with no
|
|
48
|
-
-- expiry is meant to disappear when its winner finishes. If the job row is
|
|
49
|
-
-- gone (clean, drain, obliterate, an outage…) the key is stale, so discard
|
|
50
|
-
-- it together with any pending proto-next (which would otherwise be
|
|
51
|
-
-- resurrected) and start a new window with the incoming job.
|
|
52
|
-
DELETE FROM dedup WHERE queue = p_queue AND dedup_id = v_id;
|
|
53
|
-
DELETE FROM dedup_next WHERE queue = p_queue AND dedup_id = v_id;
|
|
54
|
-
v_cur := NULL;
|
|
55
|
-
END IF;
|
|
56
|
-
|
|
57
|
-
IF v_replace THEN
|
|
58
|
-
IF v_cur IS NOT NULL THEN
|
|
59
|
-
SELECT state INTO v_state
|
|
60
|
-
FROM job WHERE queue = p_queue AND id = v_cur;
|
|
61
|
-
IF v_state = 'delayed' THEN
|
|
62
|
-
-- Drop the previous delayed job and take its place.
|
|
63
|
-
DELETE FROM job WHERE queue = p_queue AND id = v_cur;
|
|
64
|
-
PERFORM publish_event(p_queue, 'removed',
|
|
65
|
-
jsonb_build_object('jobId', v_cur, 'prev', 'delayed'));
|
|
66
|
-
PERFORM publish_event(p_queue, 'deduplicated',
|
|
67
|
-
jsonb_build_object('jobId', p_job_id, 'deduplicationId', v_id,
|
|
68
|
-
'deduplicatedJobId', v_cur));
|
|
69
|
-
-- Discard any pending proto-next stashed while the replaced job was
|
|
70
|
-
-- active, otherwise it would be resurrected when p_job_id finalizes.
|
|
71
|
-
DELETE FROM dedup_next WHERE queue = p_queue AND dedup_id = v_id;
|
|
72
|
-
IF v_keeplast THEN
|
|
73
|
-
UPDATE dedup SET job_id = p_job_id, expire_at_ms = NULL
|
|
74
|
-
WHERE queue = p_queue AND dedup_id = v_id;
|
|
75
|
-
ELSIF NOT v_extend AND COALESCE(v_ttl, 0) > 0 THEN
|
|
76
|
-
-- KEEPTTL: keep the existing window, just swap the winner.
|
|
77
|
-
UPDATE dedup SET job_id = p_job_id
|
|
78
|
-
WHERE queue = p_queue AND dedup_id = v_id;
|
|
79
|
-
ELSE
|
|
80
|
-
UPDATE dedup
|
|
81
|
-
SET job_id = p_job_id,
|
|
82
|
-
expire_at_ms = CASE WHEN COALESCE(v_ttl, 0) > 0
|
|
83
|
-
THEN p_now + v_ttl ELSE NULL END
|
|
84
|
-
WHERE queue = p_queue AND dedup_id = v_id;
|
|
85
|
-
END IF;
|
|
86
|
-
RETURN NULL;
|
|
87
|
-
ELSE
|
|
88
|
-
-- Winner is not a removable delayed job: stash proto-next if it is
|
|
89
|
-
-- active + keepLastIfActive, then deduplicate.
|
|
90
|
-
PERFORM dedup_store_next(p_queue, v_id, v_cur, p_job_id,
|
|
91
|
-
v_keeplast, p_name, p_data, p_opts);
|
|
92
|
-
RETURN v_cur;
|
|
93
|
-
END IF;
|
|
94
|
-
ELSE
|
|
95
|
-
INSERT INTO dedup (queue, dedup_id, job_id, expire_at_ms)
|
|
96
|
-
VALUES (p_queue, v_id, p_job_id,
|
|
97
|
-
CASE WHEN NOT v_keeplast AND COALESCE(v_ttl, 0) > 0
|
|
98
|
-
THEN p_now + v_ttl ELSE NULL END)
|
|
99
|
-
ON CONFLICT (queue, dedup_id) DO UPDATE
|
|
100
|
-
SET job_id = EXCLUDED.job_id, expire_at_ms = EXCLUDED.expire_at_ms;
|
|
101
|
-
RETURN NULL;
|
|
102
|
-
END IF;
|
|
103
|
-
END IF;
|
|
104
|
-
|
|
105
|
-
-- Without replace.
|
|
106
|
-
IF COALESCE(v_ttl, 0) > 0 AND v_extend THEN
|
|
107
|
-
IF v_cur IS NOT NULL THEN
|
|
108
|
-
-- Stash proto-next if active+keepLast; else extend the window (or
|
|
109
|
-
-- persist when keepLastIfActive). Either way keep the current winner.
|
|
110
|
-
IF NOT dedup_store_next(p_queue, v_id, v_cur, p_job_id,
|
|
111
|
-
v_keeplast, p_name, p_data, p_opts) THEN
|
|
112
|
-
UPDATE dedup
|
|
113
|
-
SET expire_at_ms = CASE WHEN v_keeplast THEN NULL ELSE p_now + v_ttl END
|
|
114
|
-
WHERE queue = p_queue AND dedup_id = v_id;
|
|
115
|
-
END IF;
|
|
116
|
-
PERFORM publish_event(p_queue, 'deduplicated',
|
|
117
|
-
jsonb_build_object('jobId', v_cur, 'deduplicationId', v_id,
|
|
118
|
-
'deduplicatedJobId', p_job_id));
|
|
119
|
-
RETURN v_cur;
|
|
120
|
-
END IF;
|
|
121
|
-
INSERT INTO dedup (queue, dedup_id, job_id, expire_at_ms)
|
|
122
|
-
VALUES (p_queue, v_id, p_job_id,
|
|
123
|
-
CASE WHEN v_keeplast THEN NULL ELSE p_now + v_ttl END)
|
|
124
|
-
ON CONFLICT (queue, dedup_id) DO UPDATE
|
|
125
|
-
SET job_id = EXCLUDED.job_id, expire_at_ms = EXCLUDED.expire_at_ms;
|
|
126
|
-
RETURN NULL;
|
|
127
|
-
END IF;
|
|
128
|
-
|
|
129
|
-
-- SET NX semantics (ttl>0 non-extend, or no ttl at all).
|
|
130
|
-
IF v_cur IS NOT NULL THEN
|
|
131
|
-
PERFORM dedup_store_next(p_queue, v_id, v_cur, p_job_id,
|
|
132
|
-
v_keeplast, p_name, p_data, p_opts);
|
|
133
|
-
PERFORM publish_event(p_queue, 'deduplicated',
|
|
134
|
-
jsonb_build_object('jobId', v_cur, 'deduplicationId', v_id,
|
|
135
|
-
'deduplicatedJobId', p_job_id));
|
|
136
|
-
RETURN v_cur;
|
|
137
|
-
END IF;
|
|
138
|
-
|
|
139
|
-
INSERT INTO dedup (queue, dedup_id, job_id, expire_at_ms)
|
|
140
|
-
VALUES (p_queue, v_id, p_job_id,
|
|
141
|
-
CASE WHEN NOT v_keeplast AND COALESCE(v_ttl, 0) > 0
|
|
142
|
-
THEN p_now + v_ttl ELSE NULL END)
|
|
143
|
-
ON CONFLICT (queue, dedup_id) DO UPDATE
|
|
144
|
-
SET job_id = EXCLUDED.job_id, expire_at_ms = EXCLUDED.expire_at_ms;
|
|
145
|
-
RETURN NULL;
|
|
146
|
-
END;
|
|
147
|
-
$$;
|