@marktiderman/genesis-supabase 0.4.0 → 0.6.0
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/README.md +138 -1
- package/dist/blocks.d.ts +16 -1
- package/dist/blocks.js +1 -1
- package/dist/chunk-ONBOLMXH.js +96 -0
- package/dist/chunk-ONBOLMXH.js.map +1 -0
- package/dist/{index-BSGz3RGk.d.ts → index-Ds0tO9WP.d.ts} +76 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +61 -2
- package/dist/index.js.map +1 -1
- package/dist/jobs.d.ts +185 -0
- package/dist/jobs.js +163 -0
- package/dist/jobs.js.map +1 -0
- package/dist/native.d.ts +2 -2
- package/migrations/0007_genesis_jobs.sql +352 -0
- package/migrations/0008_genesis_feature_registry.sql +412 -0
- package/migrations/tests/0007_genesis_jobs.test.sql +129 -0
- package/migrations/tests/0008_genesis_feature_registry.test.sql +180 -0
- package/package.json +65 -3
- package/dist/chunk-T2HGFC4C.js +0 -37
- package/dist/chunk-T2HGFC4C.js.map +0 -1
|
@@ -0,0 +1,352 @@
|
|
|
1
|
+
-- Genesis jobs: one background-job queue and one way to schedule work.
|
|
2
|
+
--
|
|
3
|
+
-- Two halves:
|
|
4
|
+
--
|
|
5
|
+
-- 1. A queue, private.genesis_jobs. Code (a trigger, a server function, the app) enqueues a job
|
|
6
|
+
-- of a kind with a JSON payload; a runner claims due jobs with SKIP LOCKED, each leased to a
|
|
7
|
+
-- claim id, does the work and settles each one: done, retry later, or failed. A job whose
|
|
8
|
+
-- lease runs out comes back as a redelivery; one that keeps dying fails as lease_expired.
|
|
9
|
+
-- An idempotency key makes an enqueue that repeats (a retried trigger, a double click) one job.
|
|
10
|
+
-- The runner half is `runJobs` in @marktiderman/genesis-supabase/jobs.
|
|
11
|
+
--
|
|
12
|
+
-- 2. Schedules. genesis_schedule_job(name, cron, job) asks pg_cron to POST to the app's job route
|
|
13
|
+
-- (`<url>/<job>`) through pg_net. The request carries no secret: it is signed,
|
|
14
|
+
-- `Authorization: GenesisJob t=<unix seconds>,sig=<hex HMAC-SHA256 of "<t>.<job>">`, with the
|
|
15
|
+
-- secret the route checks. A signature is good for that one job for five minutes, so the copy
|
|
16
|
+
-- pg_net keeps in its queue until it sends (net.http_request_queue, readable by more roles than
|
|
17
|
+
-- you'd think) is worth little. The URL and the secret are read from Vault by name at call
|
|
18
|
+
-- time and never stored in cron's table:
|
|
19
|
+
--
|
|
20
|
+
-- select vault.create_secret('https://app.example.com/api/jobs', 'genesis_jobs_url');
|
|
21
|
+
-- select vault.create_secret('<a long random secret>', 'genesis_jobs_secret');
|
|
22
|
+
-- select genesis_schedule_job('send-digests', '*/5 * * * *', 'digests');
|
|
23
|
+
--
|
|
24
|
+
-- The app's route is `createJobsHandler` in @marktiderman/genesis-supabase/jobs, which
|
|
25
|
+
-- checks the signature (or a plain bearer secret, for a platform cron or a person). pg_cron,
|
|
26
|
+
-- pg_net and pgcrypto are only needed for schedules: the queue works without them. Schedules
|
|
27
|
+
-- are cron jobs named `genesis-job:<name>`, so these functions never touch another cron job.
|
|
28
|
+
-- The 14-day purge is scheduled only if pg_cron is there when this runs; enable pg_cron later
|
|
29
|
+
-- and schedule it yourself: select cron.schedule('genesis-jobs-purge', '20 4 * * *',
|
|
30
|
+
-- 'select private.genesis_jobs_purge()');
|
|
31
|
+
--
|
|
32
|
+
-- Access: the queue has row level security on, no policies and no grants to anon or
|
|
33
|
+
-- authenticated. Everything goes through the functions below, granted by name to service_role
|
|
34
|
+
-- only (a server job, a trigger running as its owner). Payloads never hold secrets: they are
|
|
35
|
+
-- readable by anyone with the service role.
|
|
36
|
+
--
|
|
37
|
+
-- Use: copy this file into your app's `supabase/migrations/` under a new timestamped name
|
|
38
|
+
-- (`genesis migrate` does it). Never edit it once applied; change it with a new migration.
|
|
39
|
+
-- It stands alone.
|
|
40
|
+
--
|
|
41
|
+
-- Verify: the pgTAP test beside this file (`tests/0007_genesis_jobs.test.sql`).
|
|
42
|
+
|
|
43
|
+
create schema if not exists private;
|
|
44
|
+
|
|
45
|
+
create table private.genesis_jobs (
|
|
46
|
+
id uuid primary key default gen_random_uuid(),
|
|
47
|
+
kind text not null
|
|
48
|
+
constraint genesis_jobs_kind_format check (kind ~ '^[a-z][a-z0-9]*([-_.:][a-z0-9]+)*$' and char_length(kind) <= 100),
|
|
49
|
+
payload jsonb not null default '{}'::jsonb,
|
|
50
|
+
-- One job per (kind, key) while it is queued or running: a second enqueue returns the first.
|
|
51
|
+
-- Once the job is done, failed or cancelled the key is free again.
|
|
52
|
+
idempotency_key text
|
|
53
|
+
constraint genesis_jobs_idempotency_key_length check (char_length(idempotency_key) between 1 and 200),
|
|
54
|
+
status text not null default 'pending'
|
|
55
|
+
constraint genesis_jobs_status check (status in ('pending', 'running', 'done', 'failed', 'cancelled')),
|
|
56
|
+
run_after timestamptz not null default now(),
|
|
57
|
+
-- Attempts started (claims), including redeliveries.
|
|
58
|
+
attempts integer not null default 0,
|
|
59
|
+
max_attempts integer not null default 8
|
|
60
|
+
constraint genesis_jobs_max_attempts check (max_attempts between 1 and 100),
|
|
61
|
+
lease_until timestamptz,
|
|
62
|
+
-- The claim this job is leased to; settling with another one is stale.
|
|
63
|
+
claim_id uuid,
|
|
64
|
+
last_error text
|
|
65
|
+
constraint genesis_jobs_last_error_length check (char_length(last_error) <= 1000),
|
|
66
|
+
created_at timestamptz not null default now(),
|
|
67
|
+
updated_at timestamptz not null default now(),
|
|
68
|
+
finished_at timestamptz
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
create unique index genesis_jobs_idempotency on private.genesis_jobs (kind, idempotency_key)
|
|
72
|
+
where idempotency_key is not null and status in ('pending', 'running');
|
|
73
|
+
create index genesis_jobs_due on private.genesis_jobs (run_after) where status = 'pending';
|
|
74
|
+
create index genesis_jobs_leased on private.genesis_jobs (lease_until) where status = 'running';
|
|
75
|
+
create index genesis_jobs_finished on private.genesis_jobs (finished_at) where finished_at is not null;
|
|
76
|
+
|
|
77
|
+
alter table private.genesis_jobs enable row level security;
|
|
78
|
+
revoke all on table private.genesis_jobs from public, anon, authenticated;
|
|
79
|
+
|
|
80
|
+
-- Queues one job and returns its id. With an idempotency key, a job of the same kind and key
|
|
81
|
+
-- that is still pending or running is returned instead of a new one.
|
|
82
|
+
create or replace function public.genesis_job_enqueue(
|
|
83
|
+
p_kind text,
|
|
84
|
+
p_payload jsonb default '{}'::jsonb,
|
|
85
|
+
p_run_after timestamptz default null,
|
|
86
|
+
p_idempotency_key text default null,
|
|
87
|
+
p_max_attempts integer default 8
|
|
88
|
+
) returns uuid
|
|
89
|
+
language plpgsql
|
|
90
|
+
security definer
|
|
91
|
+
set search_path = ''
|
|
92
|
+
as $$
|
|
93
|
+
declare
|
|
94
|
+
job uuid;
|
|
95
|
+
begin
|
|
96
|
+
if p_kind is null then
|
|
97
|
+
raise exception 'genesis_job_enqueue: kind is required' using errcode = '22023';
|
|
98
|
+
end if;
|
|
99
|
+
if p_payload is null or jsonb_typeof(p_payload) <> 'object' then
|
|
100
|
+
raise exception 'genesis_job_enqueue: payload is a JSON object' using errcode = '22023';
|
|
101
|
+
end if;
|
|
102
|
+
if p_idempotency_key is not null then
|
|
103
|
+
select j.id into job from private.genesis_jobs j
|
|
104
|
+
where j.kind = p_kind and j.idempotency_key = p_idempotency_key and j.status in ('pending', 'running');
|
|
105
|
+
if found then
|
|
106
|
+
return job;
|
|
107
|
+
end if;
|
|
108
|
+
end if;
|
|
109
|
+
begin
|
|
110
|
+
insert into private.genesis_jobs (kind, payload, run_after, idempotency_key, max_attempts)
|
|
111
|
+
values (p_kind, p_payload, coalesce(p_run_after, now()), p_idempotency_key, coalesce(p_max_attempts, 8))
|
|
112
|
+
returning id into job;
|
|
113
|
+
exception when unique_violation then
|
|
114
|
+
-- Two enqueues with one key raced; the other one won.
|
|
115
|
+
select j.id into job from private.genesis_jobs j
|
|
116
|
+
where j.kind = p_kind and j.idempotency_key = p_idempotency_key and j.status in ('pending', 'running');
|
|
117
|
+
end;
|
|
118
|
+
return job;
|
|
119
|
+
end $$;
|
|
120
|
+
|
|
121
|
+
-- Hands out up to p_limit due jobs of the given kinds (all kinds when null), oldest first, each
|
|
122
|
+
-- leased for p_lease_seconds to one new claim id. Due: pending and past run_after, or running
|
|
123
|
+
-- with a lease that ran out (`redelivery`: the last attempt may have done the work). A job whose
|
|
124
|
+
-- lease ran out on its last attempt fails as lease_expired instead of coming back for ever.
|
|
125
|
+
create or replace function public.genesis_jobs_claim(
|
|
126
|
+
p_kinds text[] default null,
|
|
127
|
+
p_limit integer default 25,
|
|
128
|
+
p_lease_seconds integer default 300
|
|
129
|
+
) returns table (id uuid, kind text, payload jsonb, attempt integer, redelivery boolean, claim_id uuid)
|
|
130
|
+
language plpgsql
|
|
131
|
+
security definer
|
|
132
|
+
set search_path = ''
|
|
133
|
+
as $$
|
|
134
|
+
#variable_conflict use_column
|
|
135
|
+
declare
|
|
136
|
+
claim uuid := gen_random_uuid();
|
|
137
|
+
begin
|
|
138
|
+
if p_limit is null or p_limit not between 1 and 1000 then
|
|
139
|
+
raise exception 'genesis_jobs_claim: limit is 1 to 1000' using errcode = '22023';
|
|
140
|
+
end if;
|
|
141
|
+
if p_lease_seconds is null or p_lease_seconds not between 1 and 3600 then
|
|
142
|
+
raise exception 'genesis_jobs_claim: lease is 1 to 3600 seconds' using errcode = '22023';
|
|
143
|
+
end if;
|
|
144
|
+
|
|
145
|
+
-- Out of attempts with the lease gone: the runner died with it every time.
|
|
146
|
+
update private.genesis_jobs j
|
|
147
|
+
set status = 'failed', last_error = 'lease_expired', lease_until = null, claim_id = null,
|
|
148
|
+
finished_at = now(), updated_at = now()
|
|
149
|
+
where j.status = 'running' and j.lease_until < now() and j.attempts >= j.max_attempts
|
|
150
|
+
and (p_kinds is null or j.kind = any (p_kinds));
|
|
151
|
+
|
|
152
|
+
return query
|
|
153
|
+
with due as (
|
|
154
|
+
select j.id, j.status = 'running' as redelivery
|
|
155
|
+
from private.genesis_jobs j
|
|
156
|
+
where ((j.status = 'pending' and j.run_after <= now()) or (j.status = 'running' and j.lease_until < now()))
|
|
157
|
+
and (p_kinds is null or j.kind = any (p_kinds))
|
|
158
|
+
order by j.run_after, j.created_at
|
|
159
|
+
limit p_limit
|
|
160
|
+
for update skip locked
|
|
161
|
+
)
|
|
162
|
+
update private.genesis_jobs j
|
|
163
|
+
set status = 'running', attempts = j.attempts + 1, lease_until = now() + make_interval(secs => p_lease_seconds),
|
|
164
|
+
claim_id = claim, updated_at = now()
|
|
165
|
+
from due
|
|
166
|
+
where j.id = due.id
|
|
167
|
+
returning j.id, j.kind, j.payload, j.attempts, due.redelivery, j.claim_id;
|
|
168
|
+
end $$;
|
|
169
|
+
|
|
170
|
+
-- Records what happened to a claimed job. p_outcome: 'done'; 'retry' (back to pending after
|
|
171
|
+
-- p_retry_after_seconds, or failed when out of attempts); 'failed' (permanent). Returns false,
|
|
172
|
+
-- changing nothing, when the claim is stale (the lease ran out and the job was claimed again).
|
|
173
|
+
create or replace function public.genesis_jobs_settle(
|
|
174
|
+
p_id uuid,
|
|
175
|
+
p_claim_id uuid,
|
|
176
|
+
p_outcome text,
|
|
177
|
+
p_retry_after_seconds integer default null,
|
|
178
|
+
p_error text default null
|
|
179
|
+
) returns boolean
|
|
180
|
+
language plpgsql
|
|
181
|
+
security definer
|
|
182
|
+
set search_path = ''
|
|
183
|
+
as $$
|
|
184
|
+
declare
|
|
185
|
+
j private.genesis_jobs;
|
|
186
|
+
begin
|
|
187
|
+
if p_outcome is null or p_outcome not in ('done', 'retry', 'failed') then
|
|
188
|
+
raise exception 'genesis_jobs_settle: outcome is done, retry or failed' using errcode = '22023';
|
|
189
|
+
end if;
|
|
190
|
+
if p_outcome = 'retry' and (p_retry_after_seconds is null or p_retry_after_seconds not between 0 and 604800) then
|
|
191
|
+
raise exception 'genesis_jobs_settle: a retry needs retry_after_seconds, 0 to 604800' using errcode = '22023';
|
|
192
|
+
end if;
|
|
193
|
+
|
|
194
|
+
select * into j from private.genesis_jobs x where x.id = p_id for update;
|
|
195
|
+
if not found or j.status <> 'running' or j.claim_id is distinct from p_claim_id then
|
|
196
|
+
return false;
|
|
197
|
+
end if;
|
|
198
|
+
|
|
199
|
+
if p_outcome = 'done' then
|
|
200
|
+
update private.genesis_jobs x set status = 'done', last_error = null, lease_until = null, claim_id = null,
|
|
201
|
+
finished_at = now(), updated_at = now() where x.id = p_id;
|
|
202
|
+
elsif p_outcome = 'retry' and j.attempts < j.max_attempts then
|
|
203
|
+
update private.genesis_jobs x set status = 'pending', last_error = left(p_error, 1000),
|
|
204
|
+
run_after = now() + make_interval(secs => p_retry_after_seconds), lease_until = null, claim_id = null,
|
|
205
|
+
updated_at = now() where x.id = p_id;
|
|
206
|
+
else
|
|
207
|
+
update private.genesis_jobs x set status = 'failed', last_error = left(coalesce(p_error, 'failed'), 1000),
|
|
208
|
+
lease_until = null, claim_id = null, finished_at = now(), updated_at = now() where x.id = p_id;
|
|
209
|
+
end if;
|
|
210
|
+
return true;
|
|
211
|
+
end $$;
|
|
212
|
+
|
|
213
|
+
-- Cancels a job that hasn't run yet. A running job finishes its attempt; true when cancelled.
|
|
214
|
+
create or replace function public.genesis_job_cancel(p_id uuid) returns boolean
|
|
215
|
+
language sql
|
|
216
|
+
security definer
|
|
217
|
+
set search_path = ''
|
|
218
|
+
as $$
|
|
219
|
+
with cancelled as (
|
|
220
|
+
update private.genesis_jobs j set status = 'cancelled', finished_at = now(), updated_at = now()
|
|
221
|
+
where j.id = p_id and j.status = 'pending'
|
|
222
|
+
returning 1
|
|
223
|
+
)
|
|
224
|
+
select exists (select 1 from cancelled)
|
|
225
|
+
$$;
|
|
226
|
+
|
|
227
|
+
-- Deletes finished jobs (done, failed, cancelled) older than p_keep. Scheduled below when pg_cron
|
|
228
|
+
-- is there; returns how many went.
|
|
229
|
+
create or replace function private.genesis_jobs_purge(p_keep interval default interval '14 days') returns integer
|
|
230
|
+
language sql
|
|
231
|
+
security definer
|
|
232
|
+
set search_path = ''
|
|
233
|
+
as $$
|
|
234
|
+
with gone as (
|
|
235
|
+
delete from private.genesis_jobs j
|
|
236
|
+
where j.status in ('done', 'failed', 'cancelled') and j.finished_at < now() - p_keep
|
|
237
|
+
returning 1
|
|
238
|
+
)
|
|
239
|
+
select count(*)::integer from gone
|
|
240
|
+
$$;
|
|
241
|
+
|
|
242
|
+
-- POSTs {"job": p_job} to <genesis_jobs_url>/<p_job>, signed with genesis_jobs_secret (both read
|
|
243
|
+
-- from Vault now; the secret itself is never sent). Returns pg_net's request id. What cron runs for
|
|
244
|
+
-- each schedule.
|
|
245
|
+
create or replace function private.genesis_jobs_call(p_job text) returns bigint
|
|
246
|
+
language plpgsql
|
|
247
|
+
security definer
|
|
248
|
+
set search_path = ''
|
|
249
|
+
as $$
|
|
250
|
+
declare
|
|
251
|
+
base text;
|
|
252
|
+
secret text;
|
|
253
|
+
stamp text;
|
|
254
|
+
signature text;
|
|
255
|
+
request bigint;
|
|
256
|
+
begin
|
|
257
|
+
if p_job is null or p_job !~ '^[a-z][a-z0-9]*([-_][a-z0-9]+)*$' or char_length(p_job) > 100 then
|
|
258
|
+
raise exception 'genesis_jobs_call: job is a lowercase name like "send-digests"' using errcode = '22023';
|
|
259
|
+
end if;
|
|
260
|
+
if to_regclass('vault.decrypted_secrets') is null then
|
|
261
|
+
raise exception 'genesis_jobs_call: Vault is not installed' using errcode = '55000';
|
|
262
|
+
end if;
|
|
263
|
+
if to_regnamespace('net') is null then
|
|
264
|
+
raise exception 'genesis_jobs_call: pg_net is not installed (create extension pg_net)' using errcode = '55000';
|
|
265
|
+
end if;
|
|
266
|
+
execute 'select decrypted_secret from vault.decrypted_secrets where name = $1' into base using 'genesis_jobs_url';
|
|
267
|
+
execute 'select decrypted_secret from vault.decrypted_secrets where name = $1' into secret using 'genesis_jobs_secret';
|
|
268
|
+
if base is null or secret is null then
|
|
269
|
+
raise exception 'genesis_jobs_call: set the Vault secrets genesis_jobs_url and genesis_jobs_secret' using errcode = '55000';
|
|
270
|
+
end if;
|
|
271
|
+
if to_regprocedure('extensions.hmac(text, text, text)') is null then
|
|
272
|
+
raise exception 'genesis_jobs_call: pgcrypto is not installed (create extension pgcrypto with schema extensions)' using errcode = '55000';
|
|
273
|
+
end if;
|
|
274
|
+
stamp := floor(extract(epoch from clock_timestamp()))::bigint::text;
|
|
275
|
+
execute 'select encode(extensions.hmac($1, $2, ''sha256''), ''hex'')' into signature using stamp || '.' || p_job, secret;
|
|
276
|
+
execute 'select net.http_post(url := $1, body := $2, headers := $3, timeout_milliseconds := 10000)'
|
|
277
|
+
into request
|
|
278
|
+
using rtrim(base, '/') || '/' || p_job,
|
|
279
|
+
jsonb_build_object('job', p_job),
|
|
280
|
+
jsonb_build_object('Content-Type', 'application/json', 'Authorization', 'GenesisJob t=' || stamp || ',sig=' || signature);
|
|
281
|
+
return request;
|
|
282
|
+
end $$;
|
|
283
|
+
|
|
284
|
+
-- Schedules (or reschedules) p_job on a cron schedule, as the cron job `genesis-job:<p_name>`.
|
|
285
|
+
-- Returns cron's job id.
|
|
286
|
+
create or replace function public.genesis_schedule_job(p_name text, p_schedule text, p_job text) returns bigint
|
|
287
|
+
language plpgsql
|
|
288
|
+
security definer
|
|
289
|
+
set search_path = ''
|
|
290
|
+
as $$
|
|
291
|
+
declare
|
|
292
|
+
scheduled bigint;
|
|
293
|
+
begin
|
|
294
|
+
if p_name is null or p_name !~ '^[a-z][a-z0-9]*([-_][a-z0-9]+)*$' or char_length(p_name) > 100 then
|
|
295
|
+
raise exception 'genesis_schedule_job: name is a lowercase name like "send-digests"' using errcode = '22023';
|
|
296
|
+
end if;
|
|
297
|
+
if p_job is null or p_job !~ '^[a-z][a-z0-9]*([-_][a-z0-9]+)*$' or char_length(p_job) > 100 then
|
|
298
|
+
raise exception 'genesis_schedule_job: job is a lowercase name like "digests"' using errcode = '22023';
|
|
299
|
+
end if;
|
|
300
|
+
if to_regnamespace('cron') is null then
|
|
301
|
+
raise exception 'genesis_schedule_job: pg_cron is not installed (create extension pg_cron)' using errcode = '55000';
|
|
302
|
+
end if;
|
|
303
|
+
execute 'select cron.schedule($1, $2, $3)' into scheduled
|
|
304
|
+
using 'genesis-job:' || p_name, p_schedule, format('select private.genesis_jobs_call(%L)', p_job);
|
|
305
|
+
return scheduled;
|
|
306
|
+
end $$;
|
|
307
|
+
|
|
308
|
+
-- Removes a schedule made by genesis_schedule_job (only `genesis-job:` cron jobs). True when one was there.
|
|
309
|
+
create or replace function public.genesis_unschedule_job(p_name text) returns boolean
|
|
310
|
+
language plpgsql
|
|
311
|
+
security definer
|
|
312
|
+
set search_path = ''
|
|
313
|
+
as $$
|
|
314
|
+
declare
|
|
315
|
+
removed boolean := false;
|
|
316
|
+
begin
|
|
317
|
+
if to_regnamespace('cron') is null then
|
|
318
|
+
return false;
|
|
319
|
+
end if;
|
|
320
|
+
if p_name is null or p_name !~ '^[a-z][a-z0-9]*([-_][a-z0-9]+)*$' or char_length(p_name) > 100 then
|
|
321
|
+
return false;
|
|
322
|
+
end if;
|
|
323
|
+
execute 'select exists (select 1 from cron.job where jobname = $1)' into removed using 'genesis-job:' || p_name;
|
|
324
|
+
if removed then
|
|
325
|
+
execute 'select cron.unschedule($1)' using 'genesis-job:' || p_name;
|
|
326
|
+
end if;
|
|
327
|
+
return removed;
|
|
328
|
+
end $$;
|
|
329
|
+
|
|
330
|
+
revoke execute on function public.genesis_job_enqueue(text, jsonb, timestamptz, text, integer) from public, anon, authenticated;
|
|
331
|
+
revoke execute on function public.genesis_jobs_claim(text[], integer, integer) from public, anon, authenticated;
|
|
332
|
+
revoke execute on function public.genesis_jobs_settle(uuid, uuid, text, integer, text) from public, anon, authenticated;
|
|
333
|
+
revoke execute on function public.genesis_job_cancel(uuid) from public, anon, authenticated;
|
|
334
|
+
revoke execute on function public.genesis_schedule_job(text, text, text) from public, anon, authenticated;
|
|
335
|
+
revoke execute on function public.genesis_unschedule_job(text) from public, anon, authenticated;
|
|
336
|
+
revoke execute on function private.genesis_jobs_purge(interval) from public, anon, authenticated;
|
|
337
|
+
revoke execute on function private.genesis_jobs_call(text) from public, anon, authenticated;
|
|
338
|
+
|
|
339
|
+
grant execute on function public.genesis_job_enqueue(text, jsonb, timestamptz, text, integer) to service_role;
|
|
340
|
+
grant execute on function public.genesis_jobs_claim(text[], integer, integer) to service_role;
|
|
341
|
+
grant execute on function public.genesis_jobs_settle(uuid, uuid, text, integer, text) to service_role;
|
|
342
|
+
grant execute on function public.genesis_job_cancel(uuid) to service_role;
|
|
343
|
+
grant execute on function public.genesis_schedule_job(text, text, text) to service_role;
|
|
344
|
+
grant execute on function public.genesis_unschedule_job(text) to service_role;
|
|
345
|
+
|
|
346
|
+
-- Finished jobs go after 14 days, when pg_cron is there.
|
|
347
|
+
do $$
|
|
348
|
+
begin
|
|
349
|
+
if to_regnamespace('cron') is not null then
|
|
350
|
+
perform cron.schedule('genesis-jobs-purge', '20 4 * * *', 'select private.genesis_jobs_purge()');
|
|
351
|
+
end if;
|
|
352
|
+
end $$;
|