mirror of
https://github.com/supabase/supabase.git
synced 2026-10-17 23:29:08 +03:00
46 lines
1.4 KiB
Plaintext
46 lines
1.4 KiB
Plaintext
---
|
|
id: 'schedule-functions'
|
|
title: 'Scheduling Edge Functions'
|
|
description: 'Schedule Edge Functions with pg_cron.'
|
|
---
|
|
|
|
<div class="video-container">
|
|
<iframe
|
|
src="https://www.youtube-nocookie.com/embed/-U6DJcjVvGo"
|
|
frameBorder="1"
|
|
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
|
|
allowFullScreen
|
|
></iframe>
|
|
</div>
|
|
|
|
The hosted Supabase Platform supports the [`pg_cron` extension](/docs/guides/database/extensions/pgcron), a simple cron-based job scheduler for PostgreSQL that runs inside the database.
|
|
|
|
In combination with the [`pg_net` extension](/docs/guides/database/extensions/pgnet), this allows us to invoke Edge Functions periodically on a set schedule.
|
|
|
|
## Examples
|
|
|
|
### Invoke an Edge Function every minute
|
|
|
|
Make a POST request to a Supabase Edge Function every minute:
|
|
|
|
```sql
|
|
select
|
|
cron.schedule(
|
|
'invoke-function-every-minute',
|
|
'* * * * *', -- every minute
|
|
$$
|
|
select
|
|
net.http_post(
|
|
url:='https://project-ref.supabase.co/functions/v1/function-name',
|
|
headers:='{"Content-Type": "application/json", "Authorization": "Bearer YOUR_ANON_KEY"}'::jsonb,
|
|
body:=concat('{"time": "', now(), '"}')::jsonb
|
|
) as request_id;
|
|
$$
|
|
);
|
|
```
|
|
|
|
## Resources
|
|
|
|
- [`pg_net` extension](/docs/guides/database/extensions/pgnet)
|
|
- [`pg_cron` extension](/docs/guides/database/extensions/pgcron)
|