Tasks, scheduling and deduplication
A pushq task is one HTTP request that pushq makes for you: a URL, a method, headers and a body, plus when to send it and how to retry it. This page covers enqueuing tasks, delayed and scheduled tasks, deduplication with task_id, batch enqueue, and inspecting, running and cancelling tasks. Tasks live in a queue, whose rate limits and retry settings decide when each task is delivered.
The examples assume a client named pq (and a ctx in Go); see Install & configure an SDK. Tables use the JSON field names; the SDKs use their language’s casing (taskId in TypeScript and Java, task_id in Python, TaskID/TaskId in Go and .NET).
Enqueue a task
Section titled “Enqueue a task”POST /v1/queues/{queue}/tasks creates one task and answers 201 with it.
const task = await pq.createTask("emails", { path: "/hooks/send-welcome", jsonBody: { userId: 42 }, delaySeconds: 3600, taskId: "welcome-user-42", retry: { maxAttempts: 5 },});from pushq import Retry
task = pq.create_task( "emails", path="/hooks/send-welcome", json_body={"user_id": 42}, delay_seconds=3600, task_id="welcome-user-42", retry=Retry(max_attempts=5),)task, err := pq.CreateTask(ctx, "emails", pushq.TaskCreate{ Path: "/hooks/send-welcome", JSONBody: map[string]any{"user_id": 42}, DelaySeconds: pushq.Float64(3600), TaskID: "welcome-user-42", Retry: &pushq.Retry{MaxAttempts: pushq.Int(5)},})Task task = pq.createTask("emails", TaskCreate.builder() .path("/hooks/send-welcome") .jsonBody(Map.of("user_id", 42)) .delaySeconds(3600) .taskId("welcome-user-42") .retry(RetryConfig.builder().maxAttempts(5).build()) .build());var task = await pq.CreateTaskAsync("emails", new TaskCreate{ Path = "/hooks/send-welcome", JsonBody = new { user_id = 42 }, Delay = TimeSpan.FromHours(1), TaskId = "welcome-user-42", Retry = new RetryConfig { MaxAttempts = 5 },});curl -X POST https://api.pushqueue.dev/v1/queues/emails/tasks \ -H "Authorization: Bearer $PUSHQ_API_KEY" \ -d '{ "path": "/hooks/send-welcome", "json_body": {"user_id": 42}, "delay_seconds": 3600, "task_id": "welcome-user-42", "retry": {"max_attempts": 5} }'Task fields reference
Section titled “Task fields reference”| Parameter | Type | Default | Description |
|---|---|---|---|
url |
string | none | Absolute http or https URL, at most 2083 characters. Set exactly one of url or path. |
path |
string | none | Path starting with /, appended to the queue’s target.base_url at delivery time. The queue must have a base_url when you create the task. |
method |
string | POST |
GET, POST, PUT, PATCH, DELETE, HEAD or OPTIONS (case-insensitive). A queue target.method overrides it. |
headers |
object | none | Headers sent with the request. Queue target.headers with the same name win. |
json_body |
any JSON value | none | Body sent as JSON. Adds Content-Type: application/json unless you set a Content-Type header yourself. |
body_base64 |
string | none | Raw body bytes, base64-encoded (standard alphabet). Use for non-JSON payloads. The SDKs take raw bytes and encode them for you. |
schedule_time |
string (RFC 3339) | now | When to deliver. A time in the past means “now”. |
delay_seconds |
number | 0 |
Deliver this many seconds from now. Must be 0 or more. (.NET takes a TimeSpan named Delay.) |
dispatch_deadline_seconds |
number | 600 |
How long to wait for a response on each attempt, 15 to 1800 seconds. (.NET takes a TimeSpan named DispatchDeadline.) |
task_id |
string | generated | Your ID for the task, used for deduplication. |
retry |
object | queue settings | Per-task override of any retry field. |
Rules the API enforces (each violation is 400 invalid_argument):
- Exactly one of
urlorpath. Apathon a queue withouttarget.base_urlis400 failed_precondition. - At most one of
json_bodyorbody_base64. - At most one of
schedule_timeordelay_seconds. - A body is only allowed with
POST,PUTorPATCH. - Header names must be valid HTTP tokens, values can’t contain control characters such as CR, LF or NUL, and
Host,Content-Length,Transfer-Encoding,Connection,Keep-Alive,Upgrade,TEandTrailerare reserved.
Send to an absolute URL with a custom method, headers and body
Section titled “Send to an absolute URL with a custom method, headers and body”await pq.createTask("webhooks", { url: "https://hooks.example.com/orders", method: "PUT", headers: { "Content-Type": "text/csv", "X-Source": "billing" }, body: "id,total\n1,9.99\n", scheduleTime: new Date("2026-12-24T09:00:00Z"), dispatchDeadlineSeconds: 120,});from datetime import datetime, timezone
pq.create_task( "webhooks", url="https://hooks.example.com/orders", method="PUT", headers={"Content-Type": "text/csv", "X-Source": "billing"}, body=b"id,total\n1,9.99\n", schedule_time=datetime(2026, 12, 24, 9, 0, tzinfo=timezone.utc), dispatch_deadline_seconds=120,)at := time.Date(2026, 12, 24, 9, 0, 0, 0, time.UTC)_, err := pq.CreateTask(ctx, "webhooks", pushq.TaskCreate{ URL: "https://hooks.example.com/orders", Method: "PUT", Headers: map[string]string{"Content-Type": "text/csv", "X-Source": "billing"}, Body: []byte("id,total\n1,9.99\n"), ScheduleTime: &at, DispatchDeadlineSeconds: pushq.Float64(120),})pq.createTask("webhooks", TaskCreate.builder() .url("https://hooks.example.com/orders") .method("PUT") .header("Content-Type", "text/csv") .header("X-Source", "billing") .body("id,total\n1,9.99\n".getBytes(StandardCharsets.UTF_8)) .scheduleTime(Instant.parse("2026-12-24T09:00:00Z")) .dispatchDeadlineSeconds(120) .build());await pq.CreateTaskAsync("webhooks", new TaskCreate{ Url = "https://hooks.example.com/orders", Method = "PUT", Headers = new Dictionary<string, string> { ["Content-Type"] = "text/csv", ["X-Source"] = "billing" }, Body = Encoding.UTF8.GetBytes("id,total\n1,9.99\n"), ScheduleTime = new DateTimeOffset(2026, 12, 24, 9, 0, 0, TimeSpan.Zero), DispatchDeadline = TimeSpan.FromSeconds(120),});curl -X POST https://api.pushqueue.dev/v1/queues/webhooks/tasks \ -H "Authorization: Bearer $PUSHQ_API_KEY" \ -d '{ "url": "https://hooks.example.com/orders", "method": "PUT", "headers": {"Content-Type": "text/csv", "X-Source": "billing"}, "body_base64": "aWQsdG90YWwKMSw5Ljk5Cg==", "schedule_time": "2026-12-24T09:00:00Z", "dispatch_deadline_seconds": 120 }'A raw body without a Content-Type header is delivered as application/octet-stream.
Choose between url and path
Section titled “Choose between url and path”Use url when tasks in one queue go to different hosts. Use path with a queue target.base_url when they all go to one service: producers don’t need to know the host, and changing base_url re-points every queued task, because the path is resolved when the task is delivered, not when it is created. A queue with base_url https://api.example.com and a task with path /hooks/send delivers to https://api.example.com/hooks/send.
Delayed and scheduled tasks
Section titled “Delayed and scheduled tasks”Without schedule_time or delay_seconds, a task is due immediately. With either, it waits until that time and is then delivered as soon as the queue’s rate limits allow. Use this for reminders, delayed follow-ups and anything you want to run at a set time without a cron job. See scheduling and cancelling tasks for a full example.
Dispatch deadline (request timeout)
Section titled “Dispatch deadline (request timeout)”dispatch_deadline_seconds is how long pushq waits for your endpoint to respond on each attempt. If no response arrives in time, the attempt counts as a failure (timeout) and is retried. Raise it for slow handlers; the maximum is 30 minutes.
Task IDs and deduplication
Section titled “Task IDs and deduplication”If you don’t set task_id, the server generates a UUIDv7. If you do, it must match [A-Za-z0-9_-]{1,500} and be unique within the queue: creating a second task with an ID that is still reserved fails with 409 already_exists.
import { PushqError } from "pushq";
try { await pq.createTask("emails", { path: "/hooks/receipt", taskId: "receipt-1001" });} catch (err) { if (!(err instanceof PushqError && err.code === "already_exists")) throw err; // Already enqueued: safe to ignore.}from pushq import PushqError
try: pq.create_task("emails", path="/hooks/receipt", task_id="receipt-1001")except PushqError as err: if err.code != "already_exists": raise # Already enqueued: safe to ignore._, err := pq.CreateTask(ctx, "emails", pushq.TaskCreate{Path: "/hooks/receipt", TaskID: "receipt-1001"})if err != nil && !pushq.IsCode(err, "already_exists") { return err}// already_exists: already enqueued, safe to ignore.try { pq.createTask("emails", TaskCreate.builder().path("/hooks/receipt").taskId("receipt-1001").build());} catch (PushqException e) { if (!"already_exists".equals(e.getCode())) throw e; // Already enqueued: safe to ignore.}try{ await pq.CreateTaskAsync("emails", new TaskCreate { Path = "/hooks/receipt", TaskId = "receipt-1001" });}catch (PushqException e) when (e.Code == "already_exists"){ // Already enqueued: safe to ignore.}# A second identical request answers 409 with "code": "already_exists"curl -X POST https://api.pushqueue.dev/v1/queues/emails/tasks \ -H "Authorization: Bearer $PUSHQ_API_KEY" \ -d '{"path": "/hooks/receipt", "task_id": "receipt-1001"}'An ID stays reserved for as long as the task exists, and a task is kept for a while after it finishes. With a self-hosted server’s default settings (the hosted API may use different values):
| The task… | ID reserved until |
|---|---|
| is pending or running | it finishes |
| succeeded | 24 hours after it finished |
| failed | 7 days after it finished |
| was deleted | 1 hour after deletion (the dedup window) |
| was purged | free immediately |
Retention never drops below the dedup window (1 hour by default), so an ID always stays reserved for at least that long after the task finishes or is deleted. Self-hosters can change these with the limits.dedup_window and retention.* settings; see server configuration.
Use a deterministic task_id built from your own record ID when the same event might be enqueued twice, for example by a retried request or two workers, and you want it delivered once. The deduplication pattern shows how to build good IDs.
Task states and lifecycle
Section titled “Task states and lifecycle”| State | Meaning |
|---|---|
pending |
Waiting for its schedule time, for a retry, or for the queue’s rate limits. |
running |
Being delivered right now. |
succeeded |
Got a 2xx response. Final. |
failed |
Ran out of retries. Final. |
A task moves from pending to running, then to succeeded, or back to pending with a later schedule time when an attempt fails and retries remain. When retries run out it becomes failed and is copied to the queue’s dead-letter queue, if it has one. Deleted and purged tasks disappear from the API.
Batch enqueue up to 500 tasks
Section titled “Batch enqueue up to 500 tasks”POST /v1/queues/{queue}/tasks:batch creates up to 500 tasks in one request.
const results = await pq.createTasks("emails", [ { path: "/hooks/digest", jsonBody: { userId: 1 }, taskId: "digest-1" }, { path: "/hooks/digest", jsonBody: { userId: 2 }, taskId: "digest-2" },]);for (const r of results) { if (r.error) console.error(`item ${r.index}: ${r.error.code} ${r.error.detail}`);}results = pq.create_tasks("emails", [ {"path": "/hooks/digest", "json_body": {"user_id": 1}, "task_id": "digest-1"}, {"path": "/hooks/digest", "json_body": {"user_id": 2}, "task_id": "digest-2"},])for r in results: if r.error: print(f"item {r.index}: {r.error.code} {r.error.detail}")results, err := pq.CreateTasks(ctx, "emails", []pushq.TaskCreate{ {Path: "/hooks/digest", JSONBody: map[string]any{"user_id": 1}, TaskID: "digest-1"}, {Path: "/hooks/digest", JSONBody: map[string]any{"user_id": 2}, TaskID: "digest-2"},})for _, r := range results { if r.Error != nil { log.Printf("item %d: %s %s", r.Index, r.Error.Code, r.Error.Detail) }}List<BatchResult> results = pq.createTasks("emails", List.of( TaskCreate.builder().path("/hooks/digest").jsonBody(Map.of("user_id", 1)).taskId("digest-1").build(), TaskCreate.builder().path("/hooks/digest").jsonBody(Map.of("user_id", 2)).taskId("digest-2").build()));for (BatchResult r : results) { if (!r.isSuccess()) System.err.println("item " + r.getIndex() + ": " + r.getError().getCode());}var results = await pq.CreateTasksAsync("emails", new[]{ new TaskCreate { Path = "/hooks/digest", JsonBody = new { user_id = 1 }, TaskId = "digest-1" }, new TaskCreate { Path = "/hooks/digest", JsonBody = new { user_id = 2 }, TaskId = "digest-2" },});foreach (var r in results) if (r.Error != null) Console.Error.WriteLine($"item {r.Index}: {r.Error.Code} {r.Error.Detail}");curl -X POST https://api.pushqueue.dev/v1/queues/emails/tasks:batch \ -H "Authorization: Bearer $PUSHQ_API_KEY" \ -d '{"tasks": [ {"path": "/hooks/digest", "json_body": {"user_id": 1}, "task_id": "digest-1"}, {"path": "/hooks/digest", "json_body": {"user_id": 2}, "task_id": "digest-2"} ]}'The batch is not atomic. Each item succeeds or fails on its own, and the response has one result per item, in request order:
{ "results": [ {"index": 0, "task": {"id": "digest-1", "state": "pending"}}, {"index": 1, "error": {"code": "already_exists", "detail": "already exists"}} ]}Item error codes are invalid_argument, already_exists, not_found, failed_precondition (for example, the queue is disabled) and internal. The request answers 200 even when some items fail. It fails as a whole only if tasks is empty or has more than 500 items, the queue doesn’t exist, or the request body exceeds 8 MiB.
Use batches for fan-out jobs, such as one task per user, where a duplicate or invalid item should not block the rest. For more than 500 tasks, see bulk enqueue.
Get a task
Section titled “Get a task”GET /v1/queues/{queue}/tasks/{task_id} returns one task. By default headers and body are left out; the full view (?view=full) includes them.
const t = await pq.getTask("emails", "welcome-user-42", { view: "full" });console.log(t.state, t.dispatchCount, t.lastAttempt);t = pq.get_task("emails", "welcome-user-42", view="full")print(t.state, t.dispatch_count, t.last_attempt)t, err := pq.GetTaskFull(ctx, "emails", "welcome-user-42") // GetTask for the basic viewTask t = pq.getTaskFull("emails", "welcome-user-42"); // getTask for the basic viewvar t = await pq.GetTaskAsync("emails", "welcome-user-42", TaskView.Full);curl "https://api.pushqueue.dev/v1/queues/emails/tasks/welcome-user-42?view=full" \ -H "Authorization: Bearer $PUSHQ_API_KEY"| Field | Description |
|---|---|
id, queue, state |
Identity and current state. |
url, method |
As created. url holds the path for path-based tasks. |
headers, body_base64 |
Only in the full view. |
schedule_time |
When the task is (or was) due. Each retry moves it forward. |
created_at |
When the task was created. |
dispatch_deadline_seconds |
Effective deadline per attempt. |
retry |
The per-task override, if one was set. |
dispatch_count |
Attempts started so far. |
response_count |
Attempts that got an HTTP response (any status). |
first_attempt_at |
Time of the first attempt. |
finished_at |
When the task succeeded or failed. |
last_attempt |
at, plus status (HTTP status, if any) and error (error kind and a snippet). |
List and filter tasks
Section titled “List and filter tasks”GET /v1/queues/{queue}/tasks lists tasks, newest first.
| Query parameter | Default | Description |
|---|---|---|
state |
all | pending, running, succeeded or failed. |
id_prefix |
none | Only tasks whose ID starts with this string. |
view |
basic |
full includes headers and bodies. |
page_size |
100 |
Up to 1000. |
page_token |
none | next_page_token from the previous page. |
const page = await pq.listTasks("emails", { state: "failed", idPrefix: "receipt-", pageSize: 50 });// page.items, page.nextPageTokenpage = pq.list_tasks("emails", state="failed", id_prefix="receipt-", page_size=50)# page.items, page.next_page_tokentasks, next, err := pq.ListTasks(ctx, "emails", pushq.ListTasksParams{ State: "failed", IDPrefix: "receipt-", PageSize: 50,})TaskPage page = pq.listTasks("emails", ListTasksParams.builder() .state("failed").idPrefix("receipt-").pageSize(50).build());// page.getTasks(), page.getNextPageToken()var page = await pq.ListTasksAsync("emails", new ListTasksOptions{ State = TaskState.Failed, IdPrefix = "receipt-", PageSize = 50,});// page.Items, page.NextPageTokencurl "https://api.pushqueue.dev/v1/queues/emails/tasks?state=failed&id_prefix=receipt-&page_size=50" \ -H "Authorization: Bearer $PUSHQ_API_KEY"Pass the returned page token back to get the next page; it is empty on the last page. Use id_prefix with structured IDs (such as tenant-42-...) to look at one slice of a queue; the stats endpoint accepts the same filter.
Delivery attempts history
Section titled “Delivery attempts history”GET /v1/queues/{queue}/tasks/{task_id}/attempts returns the delivery history of a task, newest first (up to the last 1000 attempts).
const attempts = await pq.listAttempts("emails", "welcome-user-42");attempts = pq.list_attempts("emails", "welcome-user-42")attempts, err := pq.ListAttempts(ctx, "emails", "welcome-user-42")List<Attempt> attempts = pq.listAttempts("emails", "welcome-user-42");var attempts = await pq.ListAttemptsAsync("emails", "welcome-user-42");curl https://api.pushqueue.dev/v1/queues/emails/tasks/welcome-user-42/attempts \ -H "Authorization: Bearer $PUSHQ_API_KEY"{ "attempts": [ { "number": 2, "dispatch_time": "2026-11-28T10:00:01.2Z", "response_time": "2026-11-28T10:00:01.4Z", "response_status": 200, "duration_ms": 180 }, { "number": 1, "dispatch_time": "2026-11-28T10:00:00Z", "response_time": "2026-11-28T10:00:00.3Z", "response_status": 503, "error_kind": "non_2xx", "error_snippet": "upstream unavailable", "duration_ms": 290 } ]}error_kind is one of non_2xx, timeout, connect, dns, tls, config (for example, a path task on a queue whose base_url was removed) or lease_lost (the outcome was never recorded, for example because the server restarted mid-delivery). error_snippet holds the start of the response body or the error message, up to 4 KiB. Use this to see why a task is failing without adding logging to your endpoint.
Run a task now
Section titled “Run a task now”POST /v1/queues/{queue}/tasks/{task_id}:run delivers a pending task immediately, ignoring its schedule time.
await pq.runTask("emails", "welcome-user-42");pq.run_task("emails", "welcome-user-42")_, err := pq.RunTask(ctx, "emails", "welcome-user-42")pq.runTask("emails", "welcome-user-42");await pq.RunTaskAsync("emails", "welcome-user-42");curl -X POST https://api.pushqueue.dev/v1/queues/emails/tasks/welcome-user-42:run \ -H "Authorization: Bearer $PUSHQ_API_KEY"- It bypasses the queue’s rate limits and concurrency limit, and works on a paused queue.
- It counts as a normal attempt. If it fails, the usual retry rules apply; on a paused queue the retry then waits until you resume.
- It fails with
400 failed_preconditionif the queue is disabled or the task is currently running, and with404 not_foundif the task already succeeded, failed, or was deleted or purged.
Use this to test an endpoint fix on one task before resuming a paused queue, or to skip the wait on a scheduled task.
Delete or cancel a task
Section titled “Delete or cancel a task”DELETE /v1/queues/{queue}/tasks/{task_id} deletes a task in any state and answers 204.
await pq.deleteTask("emails", "welcome-user-42");pq.delete_task("emails", "welcome-user-42")err := pq.DeleteTask(ctx, "emails", "welcome-user-42")pq.deleteTask("emails", "welcome-user-42");await pq.DeleteTaskAsync("emails", "welcome-user-42");curl -X DELETE https://api.pushqueue.dev/v1/queues/emails/tasks/welcome-user-42 \ -H "Authorization: Bearer $PUSHQ_API_KEY"A deleted task is never delivered again. If it was running, that request may still reach your endpoint, but its result is ignored. The ID stays reserved for the dedup window (1 hour by default), so a task with the same ID can’t be created right away. Use this to cancel a scheduled task, such as a reminder for an order that was cancelled.
Retention of finished tasks
Section titled “Retention of finished tasks”Finished tasks and their attempt history are kept so you can inspect them: succeeded tasks for 24 hours and failed tasks for 7 days by default on a self-hosted server, never less than the dedup window. After that they are removed automatically. Self-hosters can change this with retention.succeeded and retention.failed.
Task size and scheduling limits
Section titled “Task size and scheduling limits”| Limit | Self-hosted default | Notes |
|---|---|---|
| Body size | 1 MiB | Decoded bytes. Over the limit is 400 invalid_argument. Self-hosted: limits.max_body_bytes. |
| Headers per task | 16 KiB | Sum of names and values. Self-hosted: limits.max_headers_bytes. |
| Schedule ahead | 1 year | A later schedule_time or delay_seconds is rejected. Self-hosted: limits.max_schedule_ahead. |
url length |
2083 characters | |
task_id |
500 characters | [A-Za-z0-9_-] |
dispatch_deadline_seconds |
15 to 1800 | Default 600. |
| Batch size | 500 tasks | Request body up to 8 MiB. |
A request body larger than the server accepts is rejected with 413 payload_too_large. The values above are a self-hosted server’s defaults; the hosted API may set different ones. Self-hosters can change them, see server configuration.
Read more
Section titled “Read more”- Deduplication with task IDs: enqueue exactly once from retried producers.
- Scheduling and cancelling tasks: reminders and follow-ups.
- Bulk enqueue: fan out thousands of tasks with batches.
- Delivery and webhook signatures: the request your endpoint receives.
- Retry backoff and max attempts: what happens when a delivery fails.