Clouzark

Cron jobs

Run SQL against your database on a schedule.

A cron job runs SQL against your database on a schedule, for work like purging expired rows, rolling up stats, or refreshing a materialized view. Clouzark runs the schedule itself, so the database needs no pg_cron extension.

Add a job

clouzark db cron add purge_sessions "0 3 * * *" "delete from sessions where expires_at < now()"
clouzark db cron add nightly_rollup "30 1 * * *" -f sql/rollup.sql --tz Europe/Berlin --timeout 120
clouzark db cron ls

You can also add and edit jobs from the database's Cron page in the dashboard.

Schedules

A schedule is a standard 5-field cron expression: minute, hour, day of month, month, day of week.

ScheduleRuns
*/15 * * * *Every 15 minutes
0 * * * *Every hour, on the hour
0 3 * * *Every day at 03:00
0 9 * * 1-5Weekdays at 09:00
0 0 1 * *The first of every month at midnight

Schedules are read in UTC unless you give the job a time zone (--tz, any IANA name such as America/New_York). With a time zone, a daily job stays at the same local time across daylight saving changes. Schedules can't run more often than once a minute.

How jobs run

  • As the database owner. The SQL can read and change any table, and row level security policies don't apply to it (unless a table uses FORCE ROW LEVEL SECURITY). Several ;-separated statements run in order.
  • With a timeout. A run that takes longer than the job's timeout (60 seconds by default, at most 300) is stopped and marked failed.
  • Never overlapping. If a job's previous run is still going when it's due again, the new run is skipped and recorded as skipped.
  • Without retries. A failed run waits for the next scheduled time. Write SQL that's safe to run again, so a run you trigger by hand after a failure does no harm.
  • Only while the database is active. A paused database's jobs don't run.

A database can have up to 20 cron jobs.

Check and change jobs

clouzark db cron runs purge_sessions          # recent runs: status, duration, message
clouzark db cron run purge_sessions           # run it now and wait for the result
clouzark db cron edit purge_sessions -s "0 4 * * *"
clouzark db cron disable purge_sessions       # stop scheduled runs; it can still be run by hand
clouzark db cron enable purge_sessions
clouzark db cron rm purge_sessions

Each job keeps its last 100 runs. Every run also shows up in the database's Logs, under cron.

Jobs are addressed by name or id. The same operations are available in the Management API and to AI agents.

On this page