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

active-workersclj

(active-workers pool)

Returns the number of worker threads currently executing a task.

Returns the number of worker threads currently executing a task.
sourceraw docstring

create-poolclj

(create-pool job-system task-registry emitter)
(create-pool job-system task-registry emitter config)

Creates a worker pool. Call start! to begin processing jobs. task-registry is a map of task-identifier strings to handler functions. Each handler fn receives {:job job :job-system sys :worker-id wid}.

Creates a worker pool. Call start! to begin processing jobs.
task-registry is a map of task-identifier strings to handler functions.
Each handler fn receives {:job job :job-system sys :worker-id wid}.
sourceraw docstring

force-stop!clj

(force-stop! pool)

Immediately interrupts all worker threads and stops the pool. Returns pool.

Immediately interrupts all worker threads and stops the pool. Returns pool.
sourceraw docstring

partial-successclj

(partial-success partial-results)

Wraps partial-results so the pool treats the task return as a partial success. partial-results keys: :completed-steps, :failed-steps, :retry-from-step, :results.

Wraps partial-results so the pool treats the task return as a partial success.
partial-results keys: :completed-steps, :failed-steps, :retry-from-step, :results.
sourceraw docstring

partial-success?clj

(partial-success? v)

Returns true if v was produced by partial-success.

Returns true if v was produced by partial-success.
sourceraw docstring

running?clj

(running? pool)

Returns true if the pool has been started and not yet stopped.

Returns true if the pool has been started and not yet stopped.
sourceraw docstring

start!clj

(start! pool)

Starts the worker pool. Throws if already running. Returns pool.

Starts the worker pool. Throws if already running. Returns pool.
sourceraw docstring

statsclj

(stats pool)

Returns a snapshot of pool operational metrics. Keys: :active, :completed, :failed, :errors.

Returns a snapshot of pool operational metrics.
Keys: :active, :completed, :failed, :errors.
sourceraw docstring

stop!clj

(stop! pool)
(stop! pool timeout-ms)

Gracefully stops the pool. Waits up to timeout-ms for in-flight jobs. Remaining buffered-but-unclaimed jobs stay locked in the DB and are recovered by ResetOverdueJobs after config.lock_timeout. Returns pool.

Gracefully stops the pool. Waits up to timeout-ms for in-flight jobs.
Remaining buffered-but-unclaimed jobs stay locked in the DB and are
recovered by ResetOverdueJobs after config.lock_timeout. Returns pool.
sourceraw docstring

worker-idclj

(worker-id pool)

Returns the worker-id used for all job claims from this pool.

Returns the worker-id used for all job claims from this pool.
sourceraw 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