Scheduling Edge Functions
A guide from Supabase
Apps on Plentiful run on Supabase's open-source database, sign-in, file storage and live updates, so most of this guide applies. The differences: your app reaches its database through its own server — not Supabase's data API (supabase.from(…)) — there are no Edge Functions (your app's server does that work), and scheduled work uses Jobs. Where it says "Supabase dashboard", use your app's Dashboard. Ask the builder when in doubt.
The hosted Supabase Platform supports the pg_cron extension, a recurring job scheduler in Postgres.
In combination with the pg_net extension, this allows us to invoke Edge Functions periodically on a set schedule.
To access the auth token securely for your Edge Function call, we recommend storing them in Supabase Vault.
Examples#
Invoke an Edge Function every minute#
Store project_url and publishable_key in Supabase Vault:
1select vault.create_secret('https://project-ref.supabase.co', 'project_url');2select vault.create_secret('YOUR_SUPABASE_PUBLISHABLE_KEY', 'publishable_key');Make a POST request to a Supabase Edge Function every minute:
1select2 cron.schedule(3 'invoke-function-every-minute',4 '* * * * *', -- every minute5 $$6 select7 net.http_post(8 url:= (select decrypted_secret from vault.decrypted_secrets where name = 'project_url') || '/functions/v1/function-name',9 headers:=jsonb_build_object(10 'Content-type', 'application/json',11 'Authorization', 'Bearer ' || (select decrypted_secret from vault.decrypted_secrets where name = 'publishable_key')12 ),13 body:=concat('{"time": "', now(), '"}')::jsonb14 ) as request_id;15 $$16 );