Job execution history: database persistence and in-memory ring buffer.
The ring buffer retains the last N terminal records (completed, failed, partial_success). record-start! writes to the DB only; the terminal record-* functions write to the DB and push to the buffer. observe! adds directly to the buffer without any DB interaction - useful for tests and for wiring up monitoring-event subscribers.
Thread safety: the ring buffer state lives in an atom updated with swap!.
Job execution history: database persistence and in-memory ring buffer. The ring buffer retains the last N terminal records (completed, failed, partial_success). record-start! writes to the DB only; the terminal record-* functions write to the DB and push to the buffer. observe! adds directly to the buffer without any DB interaction - useful for tests and for wiring up monitoring-event subscribers. Thread safety: the ring buffer state lives in an atom updated with swap!.
Job execution history: DB persistence and in-memory ring buffer of recent executions.
A HistoryStore wraps a database pool and an atom-backed ring buffer. Create one store per system and share it across components that record or query job history.
Typical usage:
;; Create the store (pool from the database component) (def store (job-history/create-store pool {:buffer-size 500}))
;; In the worker execution path (job-history/record-start! store job worker-id correlation-id) ;; ... job runs ... (job-history/record-completion! store (:id job) worker-id correlation-id elapsed-ms)
;; Query DB history (job-history/get-by-job-id store job-id) (job-history/query store {:from (java.util.Date.) :status "failed" :limit 50})
;; Inspect recent executions from the ring buffer (no DB) (job-history/recent store 20)
;; Wire up to monitoring events so the ring buffer is populated without ;; routing writes through this component: (monitoring/on emitter :job/completed (fn [{:keys [data]}] (job-history/observe! store data)))
;; Scheduled maintenance (job-history/expire! store)
Ring buffer notes: record-start! writes to the DB only - started records are not buffered. record-completion!, record-failure!, and record-partial-success! write to the DB and push the terminal record into the ring buffer. observe! adds directly to the buffer without any DB interaction.
Job execution history: DB persistence and in-memory ring buffer of recent executions.
A HistoryStore wraps a database pool and an atom-backed ring buffer. Create one
store per system and share it across components that record or query job history.
Typical usage:
;; Create the store (pool from the database component)
(def store (job-history/create-store pool {:buffer-size 500}))
;; In the worker execution path
(job-history/record-start! store job worker-id correlation-id)
;; ... job runs ...
(job-history/record-completion! store (:id job) worker-id correlation-id elapsed-ms)
;; Query DB history
(job-history/get-by-job-id store job-id)
(job-history/query store {:from (java.util.Date.) :status "failed" :limit 50})
;; Inspect recent executions from the ring buffer (no DB)
(job-history/recent store 20)
;; Wire up to monitoring events so the ring buffer is populated without
;; routing writes through this component:
(monitoring/on emitter :job/completed
(fn [{:keys [data]}] (job-history/observe! store data)))
;; Scheduled maintenance
(job-history/expire! store)
Ring buffer notes:
record-start! writes to the DB only - started records are not buffered.
record-completion!, record-failure!, and record-partial-success! write to
the DB and push the terminal record into the ring buffer.
observe! adds directly to the buffer without any DB interaction.Malli schemas for the job-history component.
Malli schemas for the job-history 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 |