TheDocumentation 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.
JobIdStrategy protocol decouples job ID generation from the core Proletarian machinery, allowing you to adapt ID handling to your database backend and schema. It covers three concerns: generating a new ID when a job is enqueued, encoding that ID for the database column type used in your schema (e.g. UUID, BINARY(16), BIGSERIAL), and decoding the raw database value back into the application representation.
Namespace: proletarian.protocols
Protocol Definition
Methods
Called by
proletarian.job/enqueue! before the INSERT statement is executed.- Arguments:
_(the strategy instance) - Returns: a new job ID (e.g. a
java.util.UUID), ornilif the database should generate the ID (e.g.BIGSERIAL/AUTO_INCREMENT)
Called to prepare the job ID for use as a JDBC parameter in
INSERT, UPDATE, DELETE, and SELECT statements.- Arguments:
_(the strategy instance),job-id(the value returned bygenerate-id, ornilfor DB-generated strategies) - Returns: the encoded value suitable for
PreparedStatement.setObject— e.g. ajava.util.UUIDfor PostgreSQL, or abyte[]for MySQL
Called after reading a job ID from the database
ResultSet.- Arguments:
_(the strategy instance),job-id(the raw JDBC value) - Returns: the application-level ID value — e.g. a
java.util.UUID
Built-in Strategies
Two production-ready strategies ship with Proletarian in theproletarian.job-id-strategies namespace:
->postgresql-uuid-strategy (default)
java.util.UUID via UUID/randomUUID. Passes the UUID directly to PostgreSQL’s native UUID column type — no binary encoding needed. This is the default strategy used by both enqueue! and create-queue-worker.
->mysql-uuid-strategy
java.util.UUID and encodes it as a 16-byte BINARY(16) value for storage in MySQL. Decodes the byte[] back to a UUID when reading from the database.
->db-generated-strategy
BIGSERIAL or AUTO_INCREMENT column). generate-id returns nil; the database assigns the ID on insert.
Using the MySQL Strategy
Implementing a Custom Strategy
Database-generated BIGSERIAL IDs
For schemas that useBIGSERIAL (PostgreSQL) or AUTO_INCREMENT (MySQL), generate-id should return nil to instruct Proletarian to omit the job_id column from the INSERT, letting the database assign it:
Application-generated ULID IDs
generate-id Returning nil
When generate-id returns nil, Proletarian’s db/enqueue! function passes nil to encode-id and uses the result as the job_id parameter in the PreparedStatement. Your database schema must have job_id configured with a default-generating expression (e.g. DEFAULT gen_random_uuid(), BIGSERIAL, or AUTO_INCREMENT) for this to work correctly. The enqueue! public function will return nil as the job-id in this case.