pg_cron ile Yinelenen İşleri Zamanlama
Düzenli bir zaman çizelgesinde periyodik Edge Function çağrılarını, temizlik işlerini ve veri toplama görevlerini zamanlamak için pg_cron kullanarak Supabase içindeki yinelenen işleri otomatikleştirin.
pg_cron ile Yinelenen İşleri Zamanlama, CoddyKit'te ücretsiz bir Supabase Backend as a Service dersidir. Bu, 3 dersinin 3. dersidir. Aşağıdan dersin tamamını ücretsiz okuyabilir, sonra tarayıcıda yerleşik kod editörü ve 7/24 yapay zeka koçu ile uygulamalı olarak pratik yapabilirsin. Bu, Supabase Backend as a Service öğrenme yolunun bir parçasıdır ve ilerlemeniz web ve CoddyKit uygulaması arasında senkronize olur. Supabase Backend as a Service kursu toplamda 3 dersten oluşur.
Bu dersin bazı bölümleri henüz çevrilmemiş olup İngilizce olarak gösterilmektedir.
Why Scheduled Jobs Matter
Complex workflows often need work to happen on a schedule, not just in response to a request. Think nightly cleanups, hourly aggregations, or weekly digest emails.
Supabase ships with the pg_cron extension, letting you run SQL on a recurring timetable directly inside Postgres.
- No external scheduler to maintain
- Runs close to your data
- Can trigger Edge Functions via HTTP
Enabling pg_cron
Enable the extension once per project. In the Supabase dashboard go to Database > Extensions and toggle pg_cron, or run SQL.
It creates a cron.job table that tracks every scheduled task.
create extension if not exists pg_cron;Anatomy of a Cron Schedule
pg_cron uses standard 5-field cron syntax: minute, hour, day-of-month, month, day-of-week.
0 3 * * *= every day at 03:00*/15 * * * *= every 15 minutes0 0 * * 0= every Sunday at midnight
Scheduling Your First Job
Use cron.schedule(name, schedule, sql) to register a job. Here we delete expired sessions every night at 2 AM.
select cron.schedule(
'nightly-session-cleanup',
'0 2 * * *',
$$ delete from sessions where expires_at < now() $$
);Inspecting Scheduled Jobs
Every job lives in cron.job. Query it to confirm your schedule and find the jobid you will need for updates or removal.
select jobid, schedule, jobname, active from cron.job;Reviewing Run History
pg_cron records each execution in cron.job_run_details. This is your first stop for debugging a job that did not do what you expected.
statusshows success or failurereturn_messagecarries any error text
select jobid, status, return_message, start_time
from cron.job_run_details
order by start_time desc
limit 10;Triggering an Edge Function from Cron
For real workflow logic, call an Edge Function via HTTP using the pg_net extension. The cron job fires the request; the function does the heavy lifting.
select cron.schedule(
'hourly-digest',
'0 * * * *',
$$ select net.http_post(
url := 'https://your-project.functions.supabase.co/digest',
headers := '{"Authorization": "Bearer SERVICE_ROLE_KEY"}'::jsonb
) $$
);Updating a Job
To change a schedule, simply call cron.schedule again with the same job name. pg_cron replaces the existing definition rather than creating a duplicate.
select cron.schedule(
'nightly-session-cleanup',
'0 4 * * *',
$$ delete from sessions where expires_at < now() $$
);Unscheduling a Job
Remove a job by name with cron.unschedule. Always clean up jobs you no longer need so run history stays meaningful.
select cron.unschedule('nightly-session-cleanup');Idempotency and Overlap
Scheduled jobs can overlap if one run takes longer than its interval. Design jobs to be idempotent and guard against concurrent runs.
- Use advisory locks for long jobs
- Process in bounded batches
- Mark rows as processed before acting
Timezone Awareness
pg_cron schedules run in the database server timezone, typically UTC. A job set for 0 0 * * * fires at UTC midnight, not your local midnight.
Compute local-time offsets explicitly so reports land when users expect them.
Quick Check
Test your understanding of pg_cron scheduling.
Recap
You can now automate recurring workflow steps inside Supabase.
- Enable
pg_cronand use 5-field cron syntax - Schedule with
cron.schedule, remove withcron.unschedule - Trigger Edge Functions via
net.http_post - Audit runs in
cron.job_run_details - Account for UTC timezone and overlapping runs
Yapay zeka eğitmeniyle Supabase Backend as a Service öğren — ücretsiz
Tarayıcında gerçek kod yaz ve çalıştır, 7/24 yapay zeka eğitmeninden anında yardım al; web'de ya da uygulamada kaldığın yerden devam et.
- Kurslar
- 11
- Dersler
- 40
Sıkça Sorulan Sorular
“pg_cron ile Yinelenen İşleri Zamanlama” dersi ücretsiz mi?
Evet — “pg_cron ile Yinelenen İşleri Zamanlama” dersin tüm metni burada web'de ücretsiz olarak okunabilir. Etkileşimli olarak pratik yapmak (yerleşik kod editörü ve 7/24 yapay zeka koçu) ve Supabase Backend as a Service kursunun geri kalanını açmak için CoddyKit PRO'ya yükselt. Supabase Backend as a Service kursu toplamda 3 dersten oluşur.
“pg_cron ile Yinelenen İşleri Zamanlama” dersinde ne öğreneceğim?
Düzenli bir zaman çizelgesinde periyodik Edge Function çağrılarını, temizlik işlerini ve veri toplama görevlerini zamanlamak için pg_cron kullanarak Supabase içindeki yinelenen işleri otomatikleştiri… Supabase Backend as a Service ile uygulamalı kodu tarayıcıda doğrudan çalıştırarak pratik yaparsın ve 7/24 yapay zeka koçu dersi çalışırken sorularını yanıtlar.
Supabase Backend as a Service öğrenmeye başlamak için deneyim gerekli mi?
Önceden deneyim gerekmez. CoddyKit'te Supabase Backend as a Service, başlangıçtan ileri seviyeye kadar yapılandırıldığı için buradan başlayabilir veya başından başlayıp kendi hızında ilerleme yapabilirsin. Bu, 3 dersinin 3. dersidir.
“pg_cron ile Yinelenen İşleri Zamanlama” dersi ne kadar sürer?
Çoğu CoddyKit dersi yaklaşık 5–10 dakika sürer. Her biri kısa ve etkileşimli olduğu için sabit ilerleme yaparsın ve web ile uygulama arasında tam olarak bıraktığın yerden devam edebilirsin.
Bu Supabase Backend as a Service dersinde kod yazıp çalıştırabilir miyim?
Evet. Her Supabase Backend as a Service dersi yerleşik bir kod editörü içerir, bu sayede tarayıcıda gerçek kod yazıp çalıştırabilir ve anlık yapay zeka geri bildirimi alırsın — yerel kurulum gerekli değildir.
Bu kursun tüm dersleri
- Harici Hizmetlerle Entegrasyon
- Supabase ve Çalışanlarla Görev Kuyrukları
- pg_cron ile Yinelenen İşleri Zamanlama