forked from fahrPool/fahrPool
feat: pg_cron-Job stoesst minuetlich die Dispatch-Route an
This commit is contained in:
parent
0d5b3ef10b
commit
a233cbb1b0
|
|
@ -0,0 +1,22 @@
|
||||||
|
-- Minuetlicher Anstoss der Dispatch-Route. URL und Secret stehen bewusst
|
||||||
|
-- NICHT hier (umgebungsabhaengig, kein Secret in Git), sondern in den
|
||||||
|
-- DB-Settings app.notification_dispatch_url / app.notification_dispatch_secret,
|
||||||
|
-- die pro Stack out-of-band gesetzt werden. Ist die URL leer/ungesetzt (z.B.
|
||||||
|
-- lokaler CLI-Dev-Stack), verhindert die where-Bedingung jeden http_post --
|
||||||
|
-- der Job existiert dann, tut aber nichts.
|
||||||
|
create extension if not exists pg_cron;
|
||||||
|
create extension if not exists pg_net;
|
||||||
|
|
||||||
|
select cron.schedule(
|
||||||
|
'notification-dispatch',
|
||||||
|
'* * * * *',
|
||||||
|
$$
|
||||||
|
select net.http_post(
|
||||||
|
url := current_setting('app.notification_dispatch_url', true),
|
||||||
|
headers := jsonb_build_object(
|
||||||
|
'Content-Type', 'application/json',
|
||||||
|
'Authorization', 'Bearer ' || current_setting('app.notification_dispatch_secret', true)),
|
||||||
|
body := '{}'::jsonb)
|
||||||
|
where coalesce(current_setting('app.notification_dispatch_url', true), '') <> ''
|
||||||
|
$$
|
||||||
|
);
|
||||||
Loading…
Reference in New Issue