Scheduled work
pg_cron schedules in the database that call Edge Functions through pg_net, with retries kept in tables.
There is no job worker. Recurring work is a pg_cron schedule in a migration. A schedule either runs SQL directly or calls an Edge Function with pg_net. Work that has to survive a failing provider waits in a table (an "outbox"), and the function takes a batch, counts the attempt and retries later.
The schedules
| Schedule | When | What |
|---|---|---|
send-queued-email | every minute | sends due rows of email_outbox; up to 5 attempts with backoff |
cleanup-email-outbox | daily, 03:27 UTC | deletes sent emails after 7 days, failed ones after 30 |
cleanup-activity | daily, 03:17 UTC | deletes old user activity |
reconcile-entitlements | daily, 04:43 UTC | re-fetches entitlements that end around now (Payments) |
deliver-notifications | every minute | delivers what the insert trigger missed (Notifications) |
send-digests | hourly, at :05 | sends the daily notification summaries that are due |
check-push-receipts | every 30 minutes | reads Expo's receipts and removes tokens of devices that are gone |
cleanup-notifications | daily, 03:41 UTC | deletes notifications older than 90 days |
The schedules that call a function only do so while there is work (where exists (…)), so an
idle database makes no requests.
How a schedule calls a function
select cron.schedule(
'send-queued-email',
'* * * * *',
$$
select net.http_post(
url := private.function_url('send-queued-email'),
headers := private.function_headers(),
body := '{}'::jsonb
)
where exists (select 1 from public.email_outbox where sent_at is null and send_after <= now());
$$
);private.function_url and private.function_headers read the functions' base URL and the cron
secret from Vault (functions_url, cron_secret; the local seed sets both). The function checks
the secret first (requireSecret).
Adding one
- A handler in
packages/functions/src/handlers/<name>.tsthat starts withrequireSecret(request, deps.env.CRON_SECRET), registered inhandlers/index.tsand insupabase/config.toml(verify_jwt = false). - If it works through rows, a
claim_…function that takes a batch withfor update skip lockedand counts the attempt, so overlapping runs never do one twice. - The schedule in a migration.
- A
*.db.test.tsthat calls the handler directly, wrapped inwithPausedJobs([...])so the real schedule doesn't take the test's rows first.
Locally
pg_cron runs in the local stack too. select * from cron.job_run_details order by start_time desc
shows recent runs; the function logs are in docker logs supabase_edge_runtime_listoca.