Durable render API pilot¶
Enable jobs alongside the regular PressJet API by setting PRESSJET_JOBS_DATABASE_URL to a
PostgreSQL DSN on a Unix socket or loopback. The API applies the existing renderer and worker
limits. Each secret key ID is a project. Use a stable ID for key rotation so the replacement can
read that project's jobs. Provision keys with pressjet keys new --id my-project and put the
printed key record in the existing keys file. Keep the bearer key in the calling service.
The Compose pilot uses a PostgreSQL socket shared by the API
and the database. Set PRESSJET_JOBS_POSTGRES_PASSWORD to a random hexadecimal string and
PRESSJET_PILOT_KEYS_FILE to the absolute path of a JSON key file. Start with
docker compose -f deploy/jobs.compose.yml up --build. The host port is 8092 by default.
Use a TLS ingress for remote access.
Get a PDF¶
curl --fail-with-body http://127.0.0.1:8092/v1/jobs \
-H "Authorization: Bearer $PRESSJET_API_KEY" \
-H "Idempotency-Key: invoice-604-v1" \
-H 'Content-Type: application/json' \
-d '{"version":1,"html":"<h1>Invoice 604</h1>"}'
The API returns 202 with an ID and status URL. Poll that URL with the same project key.
When the job succeeds, fetch the pdf URL with the same key. Duplicate submissions with the
same path, idempotency key and original body bytes return the existing job. Changing the path or
body returns 409. For a stored template, POST the usual {"version":1,"data":{...}} to
/v1/templates/{id}/jobs. Each job captures the template bytes and digest when it is enqueued,
so the next deployment can activate a new revision while those jobs finish.
GET /v1/jobs/usage returns UTC daily submission, success and failure counts. The pilot accepts
up to 32 active and 1,000 daily jobs per project. Outputs up to 8 MiB are retained for seven days.
Job metadata and idempotency records expire 30 days after completion. An in-flight job resumes
after the claim expires if the rendering process stops. Only the current claim can commit a
result. A render interrupted before commit can run again. Completion and webhook enqueue use one
database update, and metering counts the submitted job once. The local worker wakes immediately
after enqueue. A short poll recovers ready work from other replicas and expired leases.
Completion webhooks¶
An operator can mount a JSON file at PRESSJET_JOBS_WEBHOOKS_FILE. Map each project ID to
{"url":"https://example.org/pressjet","secret":"..."}, using 32 random bytes encoded as unpadded
base64url for the secret. Use the receiver's own endpoint. Each completion sends only job metadata.
The HTTP pilot permits loopback receivers for local tests.
Verify PressJet-Webhook-Signature against the base64url HMAC-SHA256 of
<PressJet-Webhook-Timestamp>.<raw body>. Compare in constant time, apply a short timestamp
window and deduplicate on the job ID and event type. A non-2xx response is retried with bounded
exponential backoff and jitter. A receiver can see the same event again after a lost acknowledgement.
The integration check runs against a disposable database using the URL in
PRESSJET_JOBS_DATABASE_URL.
python3 scripts/check-durable-jobs.py target/release/pressjet