Skip to main content

HTTP API

Starting the Server

srv := seqdelay.NewServer(q, seqdelay.WithServerAddr(":9280"))
srv.ListenAndServe()

Endpoints

POST /add

Add a delayed task.

{
"topic": "order-cancel",
"id": "order-123",
"body": "{\"order_id\":\"123\"}",
"delay_ms": 900000,
"ttr_ms": 30000,
"max_retries": 3
}

Response: 200 on success, 409 on duplicate.

POST /pop

Pull a ready task. Long-polls until a task is available.

{
"topic": "order-cancel",
"timeout_ms": 30000
}

Response: 200 with task data, or 200 with null data on timeout.

POST /finish

Mark a task as completed.

{
"topic": "order-cancel",
"id": "order-123"
}

Response: 200 on success, 404 if not found, 400 if not in ACTIVE state.

POST /cancel

Cancel a pending task.

{
"topic": "order-cancel",
"id": "order-123"
}

Response: 200 on success, 404 if not found.

GET /get

Query task details.

GET /get?topic=order-cancel&id=order-123

Response: 200 with full task object.

GET /stats

Queue statistics.

GET /stats

Response:

{
"code": 0,
"data": {
"topics": {
"order-cancel": { "ready": 10, "active": 3 },
"payment-notify": { "ready": 0, "active": 1 }
}
}
}

Response Format

{
"code": 0,
"message": "ok",
"data": null
}
codeMeaning
0Success
non-0Error (see message)

HTTP Status Codes

StatusWhen
200Success
400Validation error, invalid JSON
404Task not found
409Duplicate task or topic conflict
500Internal error
503Queue is closed