link,[object Object]
Skip to content

Cron & Scheduling Playbook ​

Purpose: How to run and validate scheduled jobs (locally and in staging). Audience: Developer, Admin Prerequisites: Supabase CLI running; Edge Functions deployed/served locally.

Jobs of interest

  • run-price-alerts — processes price_alerts and writes price_alert_events and price_alert_runs
  • daily-subscription-sync — syncs subscription status/invoices (plus stripe-sync, sync-invoices)
  • update-views-count — increments listing view counters
  • cleanup-duplicates — maintenance
  • process-sponsored-activations — activates scheduled sponsored listings
  • run-daily-tasks — orchestrator calling sub-jobs internally

Local execution (curl)

bash
# Price alerts
curl -X POST http://127.0.0.1:54321/functions/v1/run-price-alerts \
  -H 'Authorization: Bearer YOUR_SUPABASE_ANON_KEY'

# Subscriptions
curl -X POST http://127.0.0.1:54321/functions/v1/daily-subscription-sync \
  -H 'Authorization: Bearer YOUR_SUPABASE_ANON_KEY'
curl -X POST http://127.0.0.1:54321/functions/v1/stripe-sync \
  -H 'Authorization: Bearer YOUR_SUPABASE_ANON_KEY'
curl -X POST http://127.0.0.1:54321/functions/v1/sync-invoices \
  -H 'Authorization: Bearer YOUR_SUPABASE_ANON_KEY'

# Orchestrator
curl -X POST http://127.0.0.1:54321/functions/v1/run-daily-tasks \
  -H 'Authorization: Bearer YOUR_SUPABASE_ANON_KEY' \
  -H 'Content-Type: application/json' \
  -d '{"force":true, "slot":"manual"}'

Validation queries (SQL)

sql
-- Price alert run summary
select * from price_alert_runs order by started_at desc limit 5;

-- Events created (recent)
select alert_id, listing_id, channel, status, created_at
from price_alert_events
order by created_at desc
limit 20;

-- Subscriptions that changed in last 24h
select id, user_id, subscription_level, subscription_status, updated_at
from subscriptions
where updated_at > now() - interval '24 hours'
order by updated_at desc;

-- Email logs (if job sends email)
select recipient_email, email_type, send_status, error_message, created_at
from email_logs
order by created_at desc
limit 20;

Staging vs Production

  • Use hosted /functions/v1/<name> endpoints and a service token with least privileges for server-side invocations.
  • Keep job cadence in admin_notification_types.cron_schedule (if used) and monitor last_sent_at, total_sent_count.
  • Wire alerts to notify on failures (email/slack) when functions return non-200 or log errors.

Tips

  • Avoid overlapping runs; add lock/guard keys where needed.
  • Use idempotent inserts (e.g., on conflict do nothing) for events.
  • Maintain a job summary log (e.g., price_alert_runs) with durations and counts.

Related

  • Edge functions: docs/architecture/edge-functions.md
  • Monitoring: docs/operations/monitoring.md