Skip to content

Queue Endpoints

Background job queue management powered by BullMQ, Redis, or in-memory queues.

Configuration

json
{
  "queue": {
    "name": "default",
    "type": "bullmq",
    "concurrency": 5,
    "redis": {
      "host": "localhost",
      "port": 6379,
      "password": "{{env.REDIS_PASSWORD}}"
    },
    "defaultJobOptions": {
      "maxAttempts": 3,
      "backoff": { "type": "exponential", "delay": 1000 }
    }
  }
}
json
{
  "queue": {
    "name": "default",
    "type": "redis",
    "concurrency": 5,
    "redis": {
      "url": "{{env.REDIS_URL}}"
    }
  }
}
json
{
  "queue": {
    "name": "default",
    "type": "memory",
    "concurrency": 1
  }
}

Get Queue Stats

GET /queue/stats

Get queue statistics.

bash
curl http://localhost:3000/queue/stats \
  -H "Authorization: Bearer <token>"

Response:

json
{
  "waiting": 10,
  "active": 2,
  "completed": 5000,
  "failed": 15,
  "delayed": 5,
  "paused": 0,
  "total": 5032
}

Add Job

POST /queue/jobs

Add job to queue.

bash
curl -X POST http://localhost:3000/queue/jobs \
  -H "Authorization: Bearer <token>" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "send-email",
    "data": {
      "to": "user@example.com",
      "subject": "Hello"
    },
    "options": {
      "priority": 1,
      "delay": 60000
    }
  }'

Response:

json
{
  "id": "job-123",
  "name": "send-email",
  "status": "waiting"
}

Get Job

GET /queue/jobs/:id

Get job details.

bash
curl http://localhost:3000/queue/jobs/job-123 \
  -H "Authorization: Bearer <token>"

Response:

json
{
  "id": "job-123",
  "name": "send-email",
  "status": "completed",
  "data": {...},
  "result": {...},
  "progress": 100,
  "attempts": 1,
  "createdAt": "2024-01-01T00:00:00Z",
  "completedAt": "2024-01-01T00:00:05Z"
}

List Jobs

GET /queue/jobs

List jobs by status.

bash
curl "http://localhost:3000/queue/jobs?status=failed&limit=10" \
  -H "Authorization: Bearer <token>"

Response:

json
{
  "jobs": [
    {
      "id": "job-456",
      "name": "send-email",
      "status": "failed",
      "error": "SMTP connection failed"
    }
  ]
}

Retry Job

POST /queue/jobs/:id/retry

Retry failed job.

bash
curl -X POST http://localhost:3000/queue/jobs/job-456/retry \
  -H "Authorization: Bearer <token>"

Response:

json
{
  "success": true,
  "status": "waiting"
}

Remove Job

DELETE /queue/jobs/:id

Remove job.

bash
curl -X DELETE http://localhost:3000/queue/jobs/job-456 \
  -H "Authorization: Bearer <token>"

Clean Queue

POST /queue/clean

Clean old jobs.

bash
curl -X POST http://localhost:3000/queue/clean \
  -H "Authorization: Bearer <token>" \
  -H "Content-Type: application/json" \
  -d '{
    "status": "completed",
    "olderThan": 86400000
  }'

Response:

json
{
  "cleaned": 500
}

Pause/Resume

POST /queue/pause

Pause queue processing.

bash
curl -X POST http://localhost:3000/queue/pause \
  -H "Authorization: Bearer <token>"

POST /queue/resume

Resume queue processing.

bash
curl -X POST http://localhost:3000/queue/resume \
  -H "Authorization: Bearer <token>"

Job Options

OptionTypeDescription
prioritynumber1-20 (lower = higher priority)
delaynumberDelay in milliseconds
attemptsnumberMax retry attempts
backoffobjectRetry backoff config
timeoutnumberJob timeout in ms (default: 30000)
json
{
  "options": {
    "priority": 1,
    "delay": 60000,
    "attempts": 3,
    "backoff": {
      "type": "exponential",
      "delay": 1000
    },
    "timeout": 30000
  }
}

Priority Levels

LevelValueUse Case
LOW1Background tasks
NORMAL5Default priority
HIGH10Important tasks
CRITICAL20Urgent processing

Recurring Jobs (BullMQ)

Schedule recurring jobs with cron patterns or intervals.

Cron Pattern

bash
curl -X POST http://localhost:3000/queue/jobs \
  -H "Authorization: Bearer <token>" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "daily-report",
    "data": { "type": "summary" },
    "options": {
      "repeat": {
        "pattern": "0 9 * * *"
      }
    }
  }'

Fixed Interval

bash
curl -X POST http://localhost:3000/queue/jobs \
  -H "Authorization: Bearer <token>" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "sync-data",
    "data": { "source": "external-api" },
    "options": {
      "repeat": {
        "every": 300000,
        "limit": 100
      }
    }
  }'

Repeat Options

OptionTypeDescription
patternstringCron expression (e.g., 0 0 * * *)
everynumberInterval in milliseconds
limitnumberMax repetitions
immediatelybooleanRun immediately on creation

Job Callbacks

Trigger actions on job events.

json
{
  "name": "process-order",
  "data": { "orderId": "123" },
  "callbacks": {
    "onComplete": [
      {
        "type": "http",
        "url": "https://api.example.com/webhook",
        "method": "POST",
        "body": { "status": "completed" }
      }
    ],
    "onFailed": [
      {
        "type": "slack",
        "channel": "#alerts",
        "text": "Order processing failed"
      }
    ]
  }
}

Queue Metrics

GET /queue/metrics

Get detailed queue metrics (BullMQ only).

json
{
  "jobsProcessed": 1500,
  "jobsCompleted": 1480,
  "jobsFailed": 20,
  "jobsRetried": 15,
  "avgProcessingTime": 245,
  "jobsPerSecond": 12.5,
  "errorRate": 0.013
}

Integration with Routes

Queue jobs from route handlers:

json
{
  "path": "/orders",
  "method": "POST",
  "supabaseQueries": [{
    "table": "orders",
    "operation": "insert",
    "data": { "status": "pending" }
  }],
  "integrations": {
    "actions": [
      {
        "type": "queue",
        "queue": "default",
        "jobName": "process-order",
        "data": { "orderId": "&#123;&#123;supabase.0.id&#125;&#125;" },
        "options": { "priority": 10 }
      }
    ]
  }
}

Released under the ISC License.