Skip to content

Commit

Permalink
Add random number to notify payload to prevent deduplication
Browse files Browse the repository at this point in the history
  • Loading branch information
benjie committed Nov 14, 2023
1 parent 50752a2 commit 07f62be
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions __tests__/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ begin
returning *
into v_job;
if v_job.revision = 0 then
perform pg_notify('jobs:insert', '{"count":1}');
perform pg_notify('jobs:insert', '{"r":' || random()::text || ',"count":1}');
end if;
return v_job;
else
Expand Down Expand Up @@ -144,7 +144,7 @@ begin
and jobs.key = spec.job_key
and is_available is not true;
-- WARNING: this count is not 100% accurate; 'on conflict' clause will cause it to be an overestimate
perform pg_notify('jobs:insert', '{"count":' || array_length(specs, 1)::text || '}');
perform pg_notify('jobs:insert', '{"r":' || random()::text || ',"count":' || array_length(specs, 1)::text || '}');
-- TODO: is there a risk that a conflict could occur depending on the
-- isolation level?
return query insert into "graphile_worker"._private_jobs as jobs (
Expand Down Expand Up @@ -254,7 +254,7 @@ begin
)
returning * into v_job;
if not (v_job is null) then
perform pg_notify('jobs:insert', '{"count":-1}');
perform pg_notify('jobs:insert', '{"r":' || random()::text || ',"count":-1}');
return v_job;
end if;
-- Otherwise prevent job from retrying, and clear the key
Expand Down
6 changes: 3 additions & 3 deletions sql/000018.sql
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ begin
returning *
into v_job;
if v_job.revision = 0 then
perform pg_notify('jobs:insert', '{"count":1}');
perform pg_notify('jobs:insert', '{"r":' || random()::text || ',"count":1}');
end if;
return v_job;
else
Expand Down Expand Up @@ -116,7 +116,7 @@ begin
and is_available is not true;

-- WARNING: this count is not 100% accurate; 'on conflict' clause will cause it to be an overestimate
perform pg_notify('jobs:insert', '{"count":' || array_length(specs, 1)::text || '}');
perform pg_notify('jobs:insert', '{"r":' || random()::text || ',"count":' || array_length(specs, 1)::text || '}');

-- TODO: is there a risk that a conflict could occur depending on the
-- isolation level?
Expand Down Expand Up @@ -190,7 +190,7 @@ begin
)
returning * into v_job;
if not (v_job is null) then
perform pg_notify('jobs:insert', '{"count":-1}');
perform pg_notify('jobs:insert', '{"r":' || random()::text || ',"count":-1}');
return v_job;
end if;
-- Otherwise prevent job from retrying, and clear the key
Expand Down
6 changes: 3 additions & 3 deletions src/generated/sql.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 07f62be

Please sign in to comment.