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.
start! and stop! manage the active lifecycle of a QueueWorker created by create-queue-worker. They are thin wrappers around the proletarian.protocols/QueueWorker protocol methods of the same names. Also documented here is process-next-job!, a lower-level function that is part of the internal polling machinery but is intentionally exposed for use in tests and the REPL.
Namespace: proletarian.worker
start!
:proletarian/worker-threads (default 1). Each thread immediately begins polling the configured queue table at the interval set by :proletarian/polling-interval-ms. A small random jitter is added when scheduling subsequent threads to reduce lock contention on the job table at startup.
If :proletarian/install-jvm-shutdown-hook? was set to true when the worker was created, the JVM shutdown hook is installed at this point.
Returns true if the worker was successfully started, or nil if it was already running.
Usage
stop!
- Signals all worker threads to stop accepting new jobs.
- Waits up to
:proletarian/await-termination-timeout-ms(default10000ms) for any in-flight jobs to complete. - Calls the
:proletarian/on-shutdowncallback (if configured) after the thread pool has terminated. - Removes the JVM shutdown hook (if one was installed).
FOR UPDATE SKIP LOCKED), an interrupted job will remain in the job table and will be picked up again after the next start! or by another worker instance.
Returns true if the worker was successfully stopped, or nil if it was already stopped.
Usage
Lifecycle management with a component system
process-next-job!
SELECT ... FOR UPDATE SKIP LOCKED — and invokes handler-fn. This is the core unit of work executed by each worker thread on every polling cycle.
This function is part of the internal machinery, but is intentionally exposed as a public function for use in tests and at the REPL. It accepts no default values: you must supply all arguments explicitly. Creating a wrapper in your own codebase that provides sensible defaults is recommended.
Arguments
A JDBC
DataSource used to acquire a connection for this single poll-and-process cycle.The queue keyword to poll. Must match the value used when jobs were enqueued.
The job handler function. Called as
(handler-fn job-type payload) by default, or (handler-fn job-map) in :advanced mode (see :proletarian.worker/handler-fn-mode in config).A logger function
(event-kw data-map). No default is provided — pass (fn [_ _]) to suppress output or supply your own logger.A configuration map with internal keys (see
proletarian.worker/create-queue-worker source for the full key set). Relevant keys include::proletarian.db/job-table— job table name:proletarian.db/archived-job-table— archived job table name:proletarian.db/serializer—Serializerinstance:proletarian.db/job-id-strategy—JobIdStrategyinstance:proletarian.worker/clock—java.time.Clockinstance:proletarian.worker/handler-fn-mode—:defaultor:advanced
Return Value
| Situation | Return value |
|---|---|
| A job was found and processed without interrupt | true |
| A job was found but the thread was interrupted during processing | false |
| No job was available in the queue | nil |
Testing & REPL example
process-next-job! provides no default values for any argument. Creating a project-local wrapper function that supplies your application’s defaults makes test code more concise and ensures consistency with your production worker configuration.