1
0
Fork 0

feat: pg_cron-Job stoesst minuetlich die Dispatch-Route an

This commit is contained in:
Jonny 2026-09-04 00:03:33 +02:00
parent 0d5b3ef10b
commit a233cbb1b0
1 changed files with 22 additions and 0 deletions

View File

@ -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), '') <> ''
$$
);