A job handler is the function you provide as the second argument toDocumentation 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.
worker/create-queue-worker. Proletarian calls it each time a job is dequeued and ready to be processed. The handler is responsible for performing the actual work — sending an email, calling an external API, updating a search index, and so on. How you implement it is entirely up to you; Proletarian places no constraints on the function beyond its calling convention.
Default Mode: (job-type, payload)
By default, the handler is called with two arguments:
| Argument | Description |
|---|---|
job-type | The keyword passed as the second argument to job/enqueue! |
payload | The data map passed as the third argument to job/enqueue! |
Dispatching Multiple Job Types with a Multimethod
Adefmulti dispatched on job-type is the idiomatic way to route jobs to the correct implementation:
create-queue-worker:
Advanced Mode: Full Job Map
When you need access to job metadata — the job ID, the number of prior attempts, or the time the job was enqueued — set:proletarian/handler-fn-mode to :advanced. In this mode, the handler is called with a single argument: a map containing all of the job’s attributes.
| Key | Description |
|---|---|
:proletarian.job/job-type | Keyword identifying the job type |
:proletarian.job/payload | The job’s payload data |
:proletarian.job/job-id | Unique UUID for this job |
:proletarian.job/queue | The queue the job was enqueued on |
:proletarian.job/enqueued-at | java.time.Instant when the job was created |
:proletarian.job/process-at | java.time.Instant the job was scheduled for |
:proletarian.job/attempts | Number of attempts so far (1 on the first attempt) |
Closing Over System State
Your handler function frequently needs access to shared resources — database connections, HTTP clients, configuration values. The cleanest pattern is to close over those dependencies when the handler is defined, rather than using global state:Exception Handling
Proletarian catchesjava.lang.Exception and its subclasses thrown by the handler. When caught, the retry strategy is invoked and the job is either rescheduled or moved to the archive with a :failure status.
Other Throwable subclasses — such as java.lang.Error and its descendants — are not caught by Proletarian’s retry logic. They propagate up the call stack and will cause the worker thread to log a ::job-worker-error event and, by default, stop the worker.
