Skip to content
pushqdocs
Get started

Every pushq delivery is one HTTP request with a time limit, dispatch_deadline_seconds: 10 minutes by default, 30 minutes at most. This page covers how to run long tasks within that limit: raise the deadline for jobs that fit, accept the request fast and finish the work elsewhere, or split the job into a chain of shorter tasks.

await pq.createTask("reports", {
taskId: "monthly-report-2026-11",
path: "/hooks/build-report",
jsonBody: { month: "2026-11" },
dispatchDeadlineSeconds: 1800, // 30 minutes, the maximum
});

Use this when the job reliably finishes in well under 30 minutes and your endpoint’s own request timeout allows it.

Parameter Type Default Description
dispatch_deadline_seconds number 600 How long pushq waits for a response to one attempt, from sending the request to receiving the response status. Must be between 15 and 1800; other values are rejected with invalid_argument. Set per task.

SDKs use their language’s casing: dispatchDeadlineSeconds in TypeScript and Java, dispatch_deadline_seconds in Python, DispatchDeadlineSeconds in Go. The .NET SDK takes a TimeSpan named DispatchDeadline.

When the deadline passes before your endpoint responds, pushq:

  1. Abandons the request and closes the connection.
  2. Records the attempt with error kind timeout.
  3. Schedules a retry with the queue’s backoff, like any other failure. If retries have run out, the task becomes failed and goes to the dead-letter queue if there is one.

Closing the connection doesn’t stop your code. Whether your handler notices depends on your framework, and many keep running. The retry can then start while the first attempt is still working, so a timed-out task can run twice at the same time. Make the handler idempotent, and prefer the patterns below to a deadline your job only just fits in.

For jobs that take longer than the deadline, or that you don’t want tied to one HTTP request, have the handler save the job durably and return 202 straight away. A worker of your own (a background thread, a job runner, a process reading a jobs table) does the actual work.

app.post("/hooks/build-report", express.raw({ type: "*/*" }), async (req, res) => {
// Authenticate the request first: see /docs/concepts/delivery/
const taskId = req.get("X-Pushq-Task-Id")!;
try {
// Insert into your jobs table, ignoring a duplicate taskId.
await saveJob(taskId, JSON.parse(req.body.toString("utf8")));
} catch (err) {
console.error(err);
return res.sendStatus(500); // not saved: pushq retries
}
res.sendStatus(202); // saved: pushq marks the task succeeded
});

saveJob stands for your own code. Use this when a job runs for a long or unpredictable time and you already have somewhere to run background work.

If the work can be cut into pieces (rows of a table, pages of an API, files in a bucket), process one piece per task and enqueue the next one before responding. Each delivery stays short, a failure retries only the current piece, and pushq’s retries, rate limits and visibility apply to every step. The cursor travels in json_body, and the next task’s ID is derived from the cursor so a retried chunk can’t enqueue its successor twice.

import { Pushq, PushqError } from "pushq";
const pq = new Pushq({ apiKey: process.env.PUSHQ_API_KEY });
app.post("/hooks/export-chunk", express.raw({ type: "*/*" }), async (req, res) => {
// Authenticate the request first: see /docs/concepts/delivery/
const { export_id, cursor } = JSON.parse(req.body.toString("utf8"));
try {
// Your code: process up to 1,000 rows after `cursor`; returns null when done.
const next = await exportRows(export_id, cursor, 1000);
if (next !== null) {
await pq.createTask("exports", {
taskId: `export-${export_id}-after-${next}`,
path: "/hooks/export-chunk",
jsonBody: { export_id, cursor: next },
}).catch((err) => {
if (!(err instanceof PushqError && err.code === "already_exists")) throw err;
});
}
res.sendStatus(204);
} catch (err) {
console.error(err);
res.sendStatus(500); // pushq retries this chunk
}
});

Start the chain by enqueuing the first chunk (for example {"export_id": "exp-7", "cursor": 0}). Use this when the job is a loop over many items: it needs no extra infrastructure and each chunk finishes well inside the deadline. More multi-step shapes, including fan-out, are in chaining steps.

  • Respond only after the next chunk is enqueued. If you respond first and the enqueue fails, the chain stops silently. If the enqueue fails, return a non-2xx so pushq retries the current chunk.
  • Chunks run more than once. A chunk retried after a lost response processes its rows again. Make each chunk’s writes idempotent (upserts keyed by row ID, for example).
  • The deadline covers the whole request. It runs from sending the request until the response status arrives, including time your handler spends waiting on a slow dependency.
  • Leave headroom. Size chunks so a slow run takes a fraction of the deadline, not most of it. A chunk that sometimes times out turns into a chunk that sometimes runs twice in parallel.
  • The deadline is set per task. There is no queue-level setting; pass it on every create call that needs it. A dead-lettered copy keeps the original task’s deadline.