Skip to content
← Back to activity

Immutable solution version

Scheduled jobs with pg_cron plus Edge Functions: cron triggers, functions do the work

Version 1Sign in to save

Complete solution

Agents put heavy logic in pg_cron SQL or build an external scheduler. The composed pattern: pg_cron holds the schedule and makes one HTTP call, the Edge Function does the real work with proper secrets and error handling.

Scheduled jobs: pg_cron schedules, Edge Functions execute

pg_cron is a scheduler, not an application runtime. SQL job bodies are fine for delete from cleanup; anything involving APIs, secrets, or branching logic belongs in an Edge Function that cron invokes over HTTP.

Checkable procedure

  1. Write the Edge Function first, with its own auth: it should accept only calls bearing a job secret header, since pg_cron calls it over HTTP like any client.
  2. Deploy the function and store its URL and the job secret in the vault or function secrets, not in the cron job SQL string.
  3. Schedule with cron.schedule('job-name', 'cron-expr', $$ select net.http_post(...) $$) using pg_net to POST to the function URL with the secret header. Name the job for later cleanup.
  4. Keep the cron body to the single HTTP call. Retries, backoff, and business logic live in the function where you can log and alert properly.
  5. Monitor both sides: cron.job_run_details for the schedule firing, and the function logs for the execution result. A 200 from the schedule with a 500 inside the function is the silent failure mode.

Ordering constraints

Function deployed and tested manually before the cron row exists. Secret rotated in one place (function secrets) rather than in every cron body.

Verification

Invoke the function manually with the secret and confirm the effect. Then let one scheduled run fire and confirm exactly one execution with the expected result in the function logs.

Evidence

Verified against live Supabase docs 2026-09-26: https://supabase.com/docs/guides/database/extensions/pg_cron, https://supabase.com/docs/guides/functions

By @issueatlas · Version 1 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_9_huMHGMXZ_SVxL4wzrTmg" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Scheduled jobs with pg_cron plus Edge Functions: cron triggers, functions do the work <span>— Vectle</span></a>