Cron scheduler: evaluates crontab entries and enqueues jobs when due.
Cron state (last_execution) is persisted to known_crontabs so that the scheduler survives process restarts without double-firing. Jobs are enqueued with job_key_mode = unsafe_dedupe, so multiple scheduler instances running in parallel will not produce duplicate queue entries.
The background polling thread evaluates all registered entries on each tick and fires any whose next_run_at <= now. The poll interval is coarse (default 10 s) because cron granularity is one minute.
Relies on the ReadableColumn protocol extensions defined in database.core to return java.time.Instant values for TIMESTAMPTZ columns.
Cron scheduler: evaluates crontab entries and enqueues jobs when due. Cron state (last_execution) is persisted to known_crontabs so that the scheduler survives process restarts without double-firing. Jobs are enqueued with job_key_mode = unsafe_dedupe, so multiple scheduler instances running in parallel will not produce duplicate queue entries. The background polling thread evaluates all registered entries on each tick and fires any whose next_run_at <= now. The poll interval is coarse (default 10 s) because cron granularity is one minute. Relies on the ReadableColumn protocol extensions defined in database.core to return java.time.Instant values for TIMESTAMPTZ columns.
Cron scheduler that enqueues jobs via job-manager when schedules are due.
Each cron entry has an identifier (used as both task-identifier and job-key), a standard UNIX 5-field cron expression, and optional per-entry job creation overrides. Cron state (last_execution) is persisted to skivi.known_crontabs so the scheduler survives restarts without double-firing.
Jobs are enqueued with job_key_mode = unsafe_dedupe: if the previous run's job is still queued or in flight, the new enqueue is a no-op.
Typical usage:
(def crontabs [{:identifier "daily-report" :schedule "0 2 * * *" :spec {:queue-name "maintenance" :max-attempts 3}} {:identifier "hourly-cleanup" :schedule "0 * * * *"}])
(def scheduler (-> (scheduler/create-scheduler sys crontabs emitter {:timezone "Europe/London"}) scheduler/start!))
;; On application shutdown (scheduler/stop! scheduler 5000)
Standard events emitted: :cron/fired - a cron entry fired and a job was enqueued; :identifier in data
Cron scheduler that enqueues jobs via job-manager when schedules are due.
Each cron entry has an identifier (used as both task-identifier and job-key),
a standard UNIX 5-field cron expression, and optional per-entry job creation
overrides. Cron state (last_execution) is persisted to skivi.known_crontabs
so the scheduler survives restarts without double-firing.
Jobs are enqueued with job_key_mode = unsafe_dedupe: if the previous run's
job is still queued or in flight, the new enqueue is a no-op.
Typical usage:
(def crontabs
[{:identifier "daily-report"
:schedule "0 2 * * *"
:spec {:queue-name "maintenance" :max-attempts 3}}
{:identifier "hourly-cleanup"
:schedule "0 * * * *"}])
(def scheduler
(-> (scheduler/create-scheduler sys crontabs emitter {:timezone "Europe/London"})
scheduler/start!))
;; On application shutdown
(scheduler/stop! scheduler 5000)
Standard events emitted:
:cron/fired - a cron entry fired and a job was enqueued; :identifier in dataMalli schemas for the scheduler component.
Malli schemas for the scheduler component.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |