Skip to main content

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.

enqueue! adds a job to the Proletarian job queue by inserting a row into the job table within the supplied database connection. Because it operates directly on a java.sql.Connection, you control the transaction boundary — making it a natural fit for the Transactional Outbox Pattern, where job enqueuing and your business-logic writes share a single atomic transaction. Namespace: proletarian.job

Signature

(enqueue! conn job-type payload & options)

Required Parameters

conn
Connection
required
A JDBC database connection. The connection must be inside an active transaction when using the Transactional Outbox Pattern — if the transaction rolls back, the job is never written to the database. Obtained from your connection pool or via a helper such as next.jdbc’s jdbc/with-transaction.
job-type
keyword
required
A keyword that identifies the type of job. This value is passed as the first argument to your handler-fn when the job is processed. Use namespaced keywords (e.g. :myapp/send-email) to avoid collisions across job types.
payload
any
required
The data the job needs at processing time. It is serialized to a string by the configured :proletarian/serializer when stored, and deserialized back before being passed as the second argument to handler-fn. Must be serializable by the chosen serializer.

Options

Options are passed as trailing keyword arguments or as a single map. All keys are optional.

Scheduling

:process-at
Instant
The earliest Instant at which the job should be processed. If the instant is in the past, the job is eligible for immediate processing. If both :process-at and :process-in are supplied, :process-at takes precedence.
:process-in
Duration
A Duration to add to the current time to compute the earliest processing instant. Negative durations are treated as zero (immediate). Ignored if :process-at is also supplied.

Configuration

:proletarian/queue
keyword
default:":proletarian/default"
The name of the queue to enqueue into. Must match the :proletarian/queue configured on the worker that will process jobs from this queue.
:proletarian/job-table
string
The fully-qualified PostgreSQL or MySQL table name for the job queue. Override only if you renamed the table during schema installation.
:proletarian/serializer
Serializer
default:"Transit JSON serializer"
An implementation of the proletarian.protocols/Serializer protocol used to encode the payload before storage. Defaults to the Transit JSON serializer returned by proletarian.transit/create-serializer. Must be the same serializer used by the corresponding create-queue-worker call.
:proletarian/job-id-strategy
JobIdStrategy
default:"PostgreSQL UUID strategy"
An implementation of the proletarian.protocols/JobIdStrategy protocol used to generate and encode job IDs. Defaults to proletarian.job-id-strategies/->postgresql-uuid-strategy. Use proletarian.job-id-strategies/->mysql-uuid-strategy for MySQL deployments. Must be the same strategy used by the corresponding create-queue-worker call.
:proletarian/clock
Clock
default:"Clock/systemUTC"
The java.time.Clock instance used to determine “now” when computing process-at. Useful in tests to fix or advance time without relying on the wall clock.

Return Value

Returns the job ID as generated by the JobIdStrategy’s generate-id method — a java.util.UUID with the default strategy. Returns nil if the strategy delegates ID generation to the database (e.g. ->db-generated-strategy).

Examples

Basic usage

(require '[proletarian.job :as job])

;; Assuming `conn` is an open java.sql.Connection
(job/enqueue! conn :myapp/send-welcome-email {:user-id 42})

Transactional usage (Outbox Pattern)

Enqueue a job atomically alongside a business-logic write using next.jdbc:
(require '[next.jdbc :as jdbc]
         '[proletarian.job :as job])

(jdbc/with-transaction [tx datasource]
  ;; Business logic write
  (jdbc/execute! tx ["INSERT INTO users (email) VALUES (?)" "alice@example.com"])
  ;; Job is only visible to the worker if this transaction commits
  (job/enqueue! tx :myapp/send-welcome-email {:email "alice@example.com"}))

Scheduling a job in the future

Use :process-at with an explicit java.time.Instant:
(require '[proletarian.job :as job]
         '[java.time Instant])

(job/enqueue! conn :myapp/send-renewal-reminder {:subscription-id 99}
              :process-at (Instant/parse "2025-01-01T09:00:00Z"))
Use :process-in with a java.time.Duration for a relative delay:
(require '[proletarian.job :as job]
         '[java.time Duration])

;; Process 30 minutes from now
(job/enqueue! conn :myapp/expire-session {:session-id "abc123"}
              :process-in (Duration/ofMinutes 30))

Using a custom queue and serializer

(require '[proletarian.job :as job]
         '[proletarian.transit :as transit])

(job/enqueue! conn :myapp/generate-report {:report-id 7}
              :proletarian/queue :myapp/reports
              :proletarian/serializer (transit/create-serializer))
The :proletarian/serializer and :proletarian/job-id-strategy values used in enqueue! must match those used in the corresponding proletarian.worker/create-queue-worker call. A mismatch will cause payload decode failures or job-ID lookup errors at processing time.

Build docs developers (and LLMs) love