Documentation Index
Fetch the complete documentation index at: https://mintlify.com/msolli/proletarian/llms.txt
Use this file to discover all available pages before exploring further.
create-queue-worker constructs and returns a QueueWorker instance — the object responsible for polling the job table, deserializing payloads, and invoking your handler function. The worker is not started automatically after creation; you must call start! on it. This separation lets you wire the worker into your application’s component lifecycle (e.g. Integrant, Mount, or Component) before any polling begins.
Namespace: proletarian.worker
Signatures
Required Arguments
A JDBC
DataSource that Proletarian uses to acquire connections for polling. The worker obtains one connection per worker thread per poll cycle and manages connection lifecycle internally.The function invoked when a job is dequeued. Its calling convention depends on
:proletarian/handler-fn-mode::defaultmode (default): called as(handler-fn job-type payload)— an arity-2 function or multimethod wherejob-typeis the keyword supplied toenqueue!andpayloadis the deserialized job data.:advancedmode: called as(handler-fn job-map)— an arity-1 function receiving a map with keys:proletarian.job/job-type,:proletarian.job/payload,:proletarian.job/job-id,:proletarian.job/queue,:proletarian.job/enqueued-at,:proletarian.job/process-at, and:proletarian.job/attempts.
Options
All keys are optional. Pass options as a plain map in the third argument position.Queue & Storage
The queue this worker consumes jobs from. Must match the
:proletarian/queue used in enqueue! calls.The fully-qualified table name for pending jobs. Override only if you renamed the table during schema installation.
The fully-qualified table name for completed and failed jobs. Both successful and permanently-failed jobs are moved here after processing.
Serialization & ID Strategy
An implementation of the
Serializer protocol used to decode job payloads read from the database. Must be the same serializer used when enqueueing. Defaults to proletarian.transit/create-serializer.An implementation of the
JobIdStrategy protocol used to decode job IDs read from the database. Must match the strategy used in enqueue!. Defaults to proletarian.job-id-strategies/->postgresql-uuid-strategy.Handler Mode
Controls how
handler-fn is called. Accepted values::default—(handler-fn job-type payload):advanced—(handler-fn job-map)wherejob-mapcontains all job attributes
Retry & Failure
An arity-2 function If
(job-map exception) called when a job throws an exception. Should return a retry-strategy map:nil is returned (the default), the job is archived as failed without retrying.An arity-2 function
(job-map exception) called after a job has exhausted all retries and is being archived as permanently failed. Use it to trigger alerts or compensating actions. The return value is discarded.Logging
A logger function with signature
(event-kw data-map). Proletarian calls this whenever a notable event occurs (job started, job finished, polling error, etc.). The default implementation prints every event to stdout via println. Supply your own to integrate with clojure.tools.logging, timbre, etc.Worker Identity & Threading
A human-readable identifier for this worker instance. Used as the thread-name prefix in the internal thread pool and included in every log event under the key
:proletarian.worker/queue-worker-id. Defaults to "proletarian[<queue-name>]".Milliseconds to wait between finishing one job and polling for the next one. A small jitter is applied between worker threads to reduce lock contention on the job table.
Number of concurrent worker threads in the thread pool. Each thread independently polls for and processes jobs.
Error Handling & Shutdown
An arity-1 function
(throwable) called when an unhandled Throwable is caught in the polling loop. If it returns a truthy value, the worker is stopped. The default always returns true, meaning any unexpected polling error stops the worker.Maximum milliseconds to wait for in-flight jobs to complete when
stop! is called before the thread pool is forcibly terminated. Default is 10 seconds.When
true, Proletarian registers a JVM shutdown hook that calls stop! automatically when the JVM exits. Useful for standalone applications; consider managing lifecycle explicitly in server frameworks.A zero-arity function called after the worker has fully shut down. Use it to release resources or notify a health-check system. Return value is discarded.
Time
The
java.time.Clock used when computing timestamps for retry scheduling and archiving. Inject a fixed or offset clock in tests to control time deterministically.Return Value
Returns an implementation ofproletarian.protocols/QueueWorker. Call proletarian.worker/start! on the returned value to begin polling.
Examples
Minimal usage
Full example with multiple options
create-queue-worker only creates the worker — it does not start polling. You must call (worker/start! queue-worker) before any jobs are processed.