Background job worker implementation.
Workers poll job queues, execute jobs, and handle retries. This module provides a production-ready worker with:
Background job worker implementation. Workers poll job queues, execute jobs, and handle retries. This module provides a production-ready worker with: - Graceful shutdown - Configurable polling intervals - Automatic retry handling - Scheduled job processing - Job handler registry - Comprehensive error handling
(create-job-registry)Create a new job handler registry.
Returns: JobRegistry implementing IJobRegistry
Create a new job handler registry. Returns: JobRegistry implementing IJobRegistry
(create-worker config queue store registry)Create and start a background job worker.
Args:
config - Worker configuration map with:
:queue-name - Queue to process (keyword, required)
:poll-interval-ms - Milliseconds between polls (default 1000)
:scheduled-interval-ms - Check scheduled jobs interval (default 5000)
:virtual-threads? - Run the loop on a virtual thread (default false)
:tenant-runner - (fn [tenant-id f]) that calls f in the tenant's
schema; a job with :metadata :tenant-id fails
without one
:metrics, :error-reporter - where each run's outcome goes
(optional, see wagoe.jobs.shell.outcomes)
:on-outcome - (fn [outcome]) called after each run (optional)
:report-failures-every-ms - error-tracker throttle (default 1h)
queue - IJobQueue implementation
store - IJobStore implementation
registry - IJobRegistry implementation
Returns: Worker implementing IJobWorker
Create and start a background job worker.
Args:
config - Worker configuration map with:
:queue-name - Queue to process (keyword, required)
:poll-interval-ms - Milliseconds between polls (default 1000)
:scheduled-interval-ms - Check scheduled jobs interval (default 5000)
:virtual-threads? - Run the loop on a virtual thread (default false)
:tenant-runner - (fn [tenant-id f]) that calls f in the tenant's
schema; a job with :metadata :tenant-id fails
without one
:metrics, :error-reporter - where each run's outcome goes
(optional, see `wagoe.jobs.shell.outcomes`)
:on-outcome - (fn [outcome]) called after each run (optional)
:report-failures-every-ms - error-tracker throttle (default 1h)
queue - IJobQueue implementation
store - IJobStore implementation
registry - IJobRegistry implementation
Returns:
Worker implementing IJobWorker(create-worker-pool config queue store registry)Create multiple workers for parallel job processing.
Args: config - Worker pool configuration with: :queue-name - Queue to process :worker-count - Number of workers (default 4) :poll-interval-ms - Polling interval :scheduled-interval-ms - Scheduled check interval queue - IJobQueue implementation store - IJobStore implementation registry - IJobRegistry implementation
Returns: Vector of Worker instances
Create multiple workers for parallel job processing.
Args:
config - Worker pool configuration with:
:queue-name - Queue to process
:worker-count - Number of workers (default 4)
:poll-interval-ms - Polling interval
:scheduled-interval-ms - Scheduled check interval
queue - IJobQueue implementation
store - IJobStore implementation
registry - IJobRegistry implementation
Returns:
Vector of Worker instances(failure e)What a job failure stores and logs: no value a database driver quoted, since it lands in the jobs table (BOU-633). :type names the kind of failure, the thrown class has its own key (BOU-323).
What a job failure stores and logs: no value a database driver quoted, since it lands in the jobs table (BOU-633). :type names the kind of failure, the thrown class has its own key (BOU-323).
(fatal? t)Whether t is an error no job should swallow: the JVM may not survive it.
Out of memory, an internal VM error, a killed thread. A StackOverflowError
has unwound by the time it is caught, so it is the handler's failure, as an
AssertionError or ExceptionInInitializerError is (BOU-834).
Whether `t` is an error no job should swallow: the JVM may not survive it. Out of memory, an internal VM error, a killed thread. A StackOverflowError has unwound by the time it is caught, so it is the handler's failure, as an AssertionError or ExceptionInInitializerError is (BOU-834).
(run-pending! config queue store registry)Run every job that is due, on the calling thread, until no queue has one left. Returns how many ran. For tests: with a worker thread the outcome is a race (BOU-469). A retry or a scheduled job lands in the future, so this ends.
Run every job that is due, on the calling thread, until no queue has one left. Returns how many ran. For tests: with a worker thread the outcome is a race (BOU-469). A retry or a scheduled job lands in the future, so this ends.
(stop-worker-pool! workers)Stop all workers in a pool gracefully.
Args: workers - Vector of Worker instances
Stop all workers in a pool gracefully. Args: workers - Vector of Worker instances
(worker-pool-status workers)Get status of all workers in a pool.
Args: workers - Vector of Worker instances
Returns: Vector of worker status maps
Get status of all workers in a pool. Args: workers - Vector of Worker instances Returns: Vector of worker status maps
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 |