Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Jobs API

Job Lifecycle

pending ──▶ running ──▶ completed
               │
               ▼
           (retry) ──▶ pending   (if attempts < max_retries)
               │
               ▼
             dead                (if attempts exhausted or 4xx response)

When a job is executed, mininq sends a POST request to the callback_url with:

  • Body: the job’s payload (JSON)
  • Headers:
    • Content-Type: application/json
    • X-Mininq-Job-Id: <job-id>
    • X-Mininq-Attempt: <attempt-number>
    • X-Mininq-Queue: <queue-name>

Response handling:

  • 2xx → job marked completed, response body saved to result
  • 4xx → permanent failure, job goes directly to dead
  • 5xx / timeout / connection error → transient failure, retried up to max_retries

POST /jobs

Create a new job.

Request body:

FieldTypeRequiredDefaultDescription
callback_urlStringyesHTTP(S) URL to POST when executing
queue_nameStringno"default"Target queue (auto-created if missing)
priorityi32no0Higher values execute first
payloadObjectno{}JSON payload sent to the callback
max_retriesi32noconfig defaultMaximum retry attempts
retry_backoffStringnoconfig default"exponential", "linear", or "fixed"
base_delay_msi32noconfig defaultBase delay for retry calculation
max_delay_msi32noconfig defaultMaximum retry delay cap
timeout_msi32noconfig defaultWebhook request timeout (ms)
idempotency_keyStringnoDedup key — returns existing job if matched
delay_msi64noDelay before job becomes visible (ms)

Example:

curl -X POST http://localhost:6390/jobs \
  -H "Content-Type: application/json" \
  -d '{
    "callback_url": "https://example.com/webhook",
    "queue_name": "emails",
    "priority": 10,
    "payload": {"to": "user@example.com", "template": "welcome"},
    "max_retries": 5,
    "idempotency_key": "welcome-user-123"
  }'

Response: 201 Created (or 200 OK if idempotency key matched an existing job)

{
  "id": "019...",
  "queue_name": "emails",
  "status": "pending",
  "priority": 10,
  "payload": "{\"to\":\"user@example.com\",\"template\":\"welcome\"}",
  "callback_url": "https://example.com/webhook",
  "visible_at": "2024-01-15T10:00:01.234",
  "attempt": 0,
  "max_retries": 5,
  "timeout_ms": 30000,
  "idempotency_key": "welcome-user-123",
  "created_at": "2024-01-15T10:00:01.234",
  "updated_at": "2024-01-15T10:00:01.234"
}

Delayed Jobs

Set delay_ms to schedule a job for future execution:

curl -X POST http://localhost:6390/jobs \
  -H "Content-Type: application/json" \
  -d '{
    "callback_url": "https://example.com/webhook",
    "delay_ms": 60000
  }'

The job will remain invisible to the worker until the delay has elapsed.


GET /jobs

List jobs with optional filters.

Query parameters:

ParamTypeDefaultDescription
queueStringFilter by queue name
statusStringFilter by status (pending, running, completed, dead)
limiti6450Max results (capped at 1000)
offseti640Pagination offset

Example:

curl "http://localhost:6390/jobs?queue=emails&status=dead&limit=10"

Response: 200 OK — array of job objects.


GET /jobs/

Get a single job by ID.

curl http://localhost:6390/jobs/019...

Response: 200 OK — job object. 404 if not found.


DELETE /jobs/

Cancel a pending job. Only jobs with status pending can be cancelled.

curl -X DELETE http://localhost:6390/jobs/019...

Response: 200 OK

{
  "status": "cancelled",
  "id": "019..."
}

Returns 404 if not found, 409 if the job is not in pending status.


POST /jobs/{id}/retry

Retry a dead job. Resets it to pending with attempt count 0.

curl -X POST http://localhost:6390/jobs/019.../retry

Response: 200 OK — the reset job object. 404 if not found or not in dead status.