Liking cljdoc? Tell your friends :D

dev.skivi.worker-pool.core

Thread-pool-based worker pool that claims jobs from the queue and dispatches them to registered task functions.

All worker threads share one queue and one worker-id, so jobs are claimed atomically in batches and distributed via take-job!. The pool does not own the job-system or emitter; callers supply those at creation time.

Task functions receive a context map with :job, :job-system, and :worker-id. They signal outcomes as follows: • return any value (including nil) - job succeeds (WorkerCompletesJob) • return (partial-success m) - partial success (WorkerReportsPartialSuccess) • throw any Throwable - job fails (WorkerFailsJob)

Events emitted: :pool/start - pool is started (includes :concurrency) :pool/stop - pool has stopped (includes :forced? when force-stop!) :job/completed - task fn returned normally :job/failed - task fn threw; job retry scheduled :job/exhausted - task fn threw on the final allowed attempt :job/partial-success - task fn returned a partial-success value :worker/error - infrastructure exception outside task execution

Thread-pool-based worker pool that claims jobs from the queue and dispatches
them to registered task functions.

All worker threads share one queue and one worker-id, so jobs are claimed
atomically in batches and distributed via take-job!. The pool does not own the
job-system or emitter; callers supply those at creation time.

Task functions receive a context map with :job, :job-system, and :worker-id.
They signal outcomes as follows:
  • return any value (including nil) - job succeeds (WorkerCompletesJob)
  • return (partial-success m)       - partial success (WorkerReportsPartialSuccess)
  • throw any Throwable              - job fails   (WorkerFailsJob)

Events emitted:
  :pool/start          - pool is started (includes :concurrency)
  :pool/stop           - pool has stopped (includes :forced? when force-stop!)
  :job/completed       - task fn returned normally
  :job/failed          - task fn threw; job retry scheduled
  :job/exhausted       - task fn threw on the final allowed attempt
  :job/partial-success - task fn returned a partial-success value
  :worker/error        - infrastructure exception outside task execution
raw docstring

dev.skivi.worker-pool.interface

Concurrent worker pool that claims jobs from the queue and executes task handlers.

All workers share a single local queue backed by job-manager. The pool uses one worker-id for all job claims; see worker-id to retrieve it.

Task functions are plain Clojure functions keyed by task-identifier string:

(def tasks {"send-email" (fn [{:keys [job]}] (send! (:payload job))) "resize-image" (fn [{:keys [job job-system worker-id]}] ...)})

A task fn receives a context map with: :job - the full job map returned by job-manager/get-jobs :job-system - the {:pool :validator} system map :worker-id - the pool's worker-id string

Task outcome is determined by the return value or exception: • return any value (including nil) - job completes successfully • return (partial-success m) - job reported as partial success • throw any Throwable - job is failed (retry or exhaust)

Typical usage:

(def pool (-> (worker-pool/create-pool sys tasks emitter {:concurrency 4}) worker-pool/start!))

;; On application shutdown (worker-pool/stop! pool 15000)

Standard events emitted by the pool (via the supplied emitter): :pool/start - pool started; :concurrency in data :pool/stop - pool stopped; :forced? in data :job/completed - task fn returned normally :job/failed - task fn threw; retry scheduled :job/exhausted - task fn threw on the final allowed attempt :job/partial-success - task fn returned a partial-success value :worker/error - infrastructure exception outside task execution

Concurrent worker pool that claims jobs from the queue and executes task handlers.

All workers share a single local queue backed by job-manager. The pool uses one
worker-id for all job claims; see worker-id to retrieve it.

Task functions are plain Clojure functions keyed by task-identifier string:

  (def tasks
    {"send-email"  (fn [{:keys [job]}] (send! (:payload job)))
     "resize-image" (fn [{:keys [job job-system worker-id]}] ...)})

A task fn receives a context map with:
  :job        - the full job map returned by job-manager/get-jobs
  :job-system - the {:pool :validator} system map
  :worker-id  - the pool's worker-id string

Task outcome is determined by the return value or exception:
  • return any value (including nil) - job completes successfully
  • return (partial-success m)       - job reported as partial success
  • throw any Throwable               - job is failed (retry or exhaust)

Typical usage:

  (def pool
    (-> (worker-pool/create-pool sys tasks emitter {:concurrency 4})
        worker-pool/start!))

  ;; On application shutdown
  (worker-pool/stop! pool 15000)

Standard events emitted by the pool (via the supplied emitter):
  :pool/start          - pool started; :concurrency in data
  :pool/stop           - pool stopped; :forced? in data
  :job/completed       - task fn returned normally
  :job/failed          - task fn threw; retry scheduled
  :job/exhausted       - task fn threw on the final allowed attempt
  :job/partial-success - task fn returned a partial-success value
  :worker/error        - infrastructure exception outside task execution
raw docstring

dev.skivi.worker-pool.schema

Malli schemas for the worker-pool component.

Malli schemas for the worker-pool component.
raw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
Move to previous article
Move to next article
Ctrl+/Jump to the search field
× close