Skip to content
pushqdocs
Get started

pushq retries every failed delivery with backoff, and a failure is any response that isn’t 2xx, including 400, 404 and 422. When a task can never succeed (the record it points to was deleted, the payload is invalid, a downstream API rejects it for good), you have to stop the retries yourself: acknowledge it with a 2xx and record the failure, cap its attempts, delete it, or let it land in a dead-letter queue.

Your handler knows which errors are permanent. Return a 2xx for those so pushq marks the task succeeded and stops, and keep your own record of what went wrong. Return a non-2xx (or let the request fail) only for errors a retry can fix.

app.post("/hooks/send-welcome", express.raw({ type: "*/*" }), async (req, res) => {
// Authenticate the request first: see /docs/concepts/delivery/
const taskId = req.get("X-Pushq-Task-Id");
const { user_id } = JSON.parse(req.body.toString("utf8"));
try {
const user = await findUser(user_id);
if (!user) {
// Permanent: retrying won't make the user exist. Record it and acknowledge.
await recordFailure(taskId, "user not found");
return res.status(200).json({ skipped: "user not found" });
}
await sendWelcomeEmail(user);
res.sendStatus(204);
} catch (err) {
// Temporary (timeout, 5xx from the email API): let pushq retry.
console.error(err);
res.sendStatus(500);
}
});

findUser, recordFailure and sendWelcomeEmail stand for your own code. Use this when your handler can tell a permanent error from a temporary one, which is most of the time.

Outcome of an attempt What pushq does
Any 2xx status Marks the task succeeded. No more attempts.
Any other status, including 400, 401, 404, 410, 422, 500 Schedules a retry with backoff.
429 or 503 with a Retry-After header Retries after the Retry-After delay (capped at the queue’s max_backoff_seconds) and briefly holds back the whole queue.
Timeout, connection refused, DNS or TLS error Schedules a retry with backoff.

There is no status code that means “don’t retry”. Retries end only when the task succeeds, when its retry limits run out, or when you delete it. When the limits run out, the task becomes failed and, if the queue has a dead-letter queue, a copy goes there. The details are on the retries page.

Cap retries with max_attempts and a dead-letter queue

Section titled “Cap retries with max_attempts and a dead-letter queue”

When you can’t tell permanent errors apart (for example, a third-party endpoint you don’t control), limit how long pushq keeps trying. Set retry.max_attempts on the task (it counts the first attempt, so 5 means one try and four retries) and give the queue a dead-letter queue to collect what runs out. The dead-letter queue must already exist.

await pq.patchQueue("webhooks", { deadLetterQueue: "webhooks-dead" });
await pq.createTask("webhooks", {
taskId: "order-created-1234",
url: "https://partner.example.com/events",
jsonBody: { event: "order.created", order_id: 1234 },
retry: { maxAttempts: 5 },
});

Use this when a task is worth a few tries but not the queue default of 100 attempts. To change the limit for every task in the queue, set retry.max_attempts on the queue instead; see queues. SDKs use their own casing for these fields (maxAttempts in TypeScript and Java, max_attempts in Python, MaxAttempts in Go and .NET).

Deleting a task stops it immediately, whatever state it is in. Use it for a task that is already retrying and that you know is hopeless.

await pq.deleteTask("webhooks", "order-created-1234");
  • A pending task is never dispatched again.
  • A running task’s in-flight request is not cancelled, but its result is discarded and it won’t be retried.
  • A deleted task is not copied to the dead-letter queue, and its ID stays reserved for the dedup window (1 hour on self-hosted defaults). See task deduplication.

To stop every task in a queue at once, pause the queue (dispatch stops, tasks are kept) or purge it (tasks are deleted).

  • Returning 4xx for bad input retries it up to 100 times. Validation errors are permanent; answer them with a 2xx and record the problem.
  • Returning 2xx too eagerly loses work. Only acknowledge errors you are sure a retry can’t fix. Timeouts and 5xx from your dependencies usually clear up.
  • A failure in the dead-letter queue retries too. Dead-lettered copies get the dead-letter queue’s own retry settings and a new task ID. Give that queue a sensible max_attempts, and see replaying dead letters.
  • The dead-letter queue must exist. If the queue named in dead_letter_queue doesn’t exist when a task runs out of retries, the copy is not made (the server logs the error) and only the failed task remains.
  • Use Retry-After for “not yet”, not “never”. A 429 or 503 with Retry-After delays the retry; it doesn’t stop it.