安排边缘函数
托管的 Supabase 平台支持 pg_cron 扩展,这是 Postgres 中的一个定期任务调度器。
🌐 The hosted Supabase Platform supports the pg_cron extension, a recurring job scheduler in Postgres.
结合pg_net扩展,这让我们可以按设定的时间表定期调用 Edge 函数。
🌐 In combination with the pg_net extension, this allows us to invoke Edge Functions periodically on a set schedule.
为了安全地访问你的 Edge Function 调用的认证令牌,我们建议将它们存储在 Supabase Vault。
🌐 To access the auth token securely for your Edge Function call, we recommend storing them in Supabase Vault.
示例 #
🌐 Examples
每分钟调用一次 Edge 函数 #
🌐 Invoke an Edge Function every minute
将 project_url 和 publishable_key 存储在 Supabase Vault 中:
🌐 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');每分钟向 Supabase Edge Function 发送一次 POST 请求:
🌐 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 'apikey', (select decrypted_secret from vault.decrypted_secrets where name = 'publishable_key')12 ),13 body:=concat('{"time": "', now(), '"}')::jsonb14 ) as request_id;15 $$16 );资源 #
🌐 Resources