Run Scheduled and Recurring Tasks with Cron
Cron runs commands on time-based schedules but keeps no job history, has no retries and does no concurrency control, so reliability depends on the job itself. The guide covers the five-field schedule syntax, including the day-of-month/weekday OR pitfall and timezone/DST issues, and recommends idempotent upserts, structured start/success/error logs, explicit connection cleanup, and Postgres advisory locks to prevent overlapping runs. On Railway, cron triggers a service's start command in UTC with a 5-minute minimum interval and a single active execution. A process left alive by open handles or pending promises causes later runs to be skipped.
Related posts
- Postgres as a CRON Server
Supabase mediumAdeptPostgres can act as a cron server by combining the pg_cron extension for scheduling with the pgsql-http extension for outbound HTTP calls, letting a scheduled SQL statement POST to a webhook every minute. The walkthrough covers enabling both extensions, granting cron schema access to non-superuser roles, cron syntax, and inspecting or unscheduling jobs via cron.job and cron.job_run_details. pg_cron runs jobs in background workers so slow endpoints don't block core Postgres, but setting http.timeout_msec to fail fast is still recommended. Suggested uses include batching welcome emails, aggregating data and deleting old rows.
- How to fix missing table errors in pg_cron
Neon mediumAdept
pg_cron stores scheduled jobs as raw SQL text, separate from Postgres' system catalogs, so dropping a table leaves jobs that fail every run with "relation does not exist" and fill cron.job_run_details with errors. Manual unscheduling, defensive DO blocks and cleanup jobs all leave gaps. A roughly 30-line PL/pgSQL event trigger on sql_drop closes them: it calls pg_event_trigger_dropped_objects() and unschedules any cron.job whose command mentions the dropped table name. The post also lists operational practices, such as explicit statement_timeout, setting search_path, and purging run history, and says when Airflow or Inngest fit better than pg_cron.
- Cron Jobs on Railway
Railway mediumAdeptBefore native cron support existed, Railway cron jobs could be run as an ordinary long-lived service that schedules work with a language-level library. The example scaffolds a TypeScript package with DTS, uses node-cron to log a message every minute, points the start script at the built dist output, and deploys with `railway up` without extra configuration. An update notes that Railway now offers native Cron Jobs, which may be the better option.
- Your Neon Functions can now run on a schedule
Neon mediumAdept
Neon Function Triggers let Neon invoke a deployed Node.js function on a cron schedule. Because the timer lives outside the Postgres compute, scheduled jobs keep working with scale to zero, unlike pg_cron, which only runs while the compute is up and can only execute SQL. Triggers are branch-scoped, and child branches inherit their parent's triggers in a disabled state, so branching production doesn't double-fire jobs. A worked example uses a Hono handler that verifies the X-Neon-Trigger-Invocation-Id header, reads scheduled_at from the request body, and uses ON CONFLICT DO NOTHING to stay idempotent, plus the API call that creates a 15-minute schedule.
- Executing Cron Scripts Reliably At Scale
Slack Engineering mediumAdeptSlack replaced a single cron box running all scripts from one crontab with a distributed cron execution service built mostly from existing infrastructure. A Go "Scheduled Job Conductor" on Kubernetes (Bedrock) uses leader election so one pod schedules while standby pods wait to take over, and it avoids shutting down at the top of a minute. The heavy work is offloaded to Slack's Kafka/Redis-backed Job Queue, which runs about 9 billion jobs a day. A Vitess table records each run's state, replacing flock-based locking for deduplication and backing a status page for engineers. The team chose a single active scheduler over synchronizing multiple nodes because leader failover is fast and scripts don't execute on the scheduler itself.