Skip to content
pushqdocs
Get started

This pattern covers delayed and scheduled tasks in pushq: sending a request later (a reminder, a follow-up email, a trial-expiry check), cancelling it when it is no longer needed, and moving it to a different time. You give each scheduled task a predictable task ID, so you can cancel it later without storing anything.

A user signs up. If they haven’t activated in three days, send a follow-up email. If they activate before then, cancel it.

import { PushqError } from "pushq";
// At signup: follow up in 3 days.
await pq.createTask("emails", {
taskId: "followup-user-42",
path: "/hooks/follow-up",
jsonBody: { userId: 42 },
delaySeconds: 3 * 24 * 3600,
});
// When the user activates: cancel it.
try {
await pq.deleteTask("emails", "followup-user-42");
} catch (err) {
if (!(err instanceof PushqError && err.code === "not_found")) throw err; // already cancelled
}

The examples assume a client named pq (see install and configure an SDK). The text uses JSON field names; the SDKs use their language’s casing (delaySeconds in TypeScript and Java, delay_seconds in Python, DelaySeconds in Go, and a TimeSpan named Delay in .NET).

Use this when something should happen later unless something else happens first: reminders, follow-ups, abandoned-cart nudges, trial-expiry checks, “close this ticket if no reply in 7 days”.

A deterministic task ID (followup-user-42) does double duty: it makes enqueueing idempotent (a second create for the same user returns already_exists instead of a second follow-up), and it lets you cancel the task from anywhere that knows the user ID.

Delay a task or schedule it at an exact time

Section titled “Delay a task or schedule it at an exact time”

Set one of these on the task, not both (sending both is invalid_argument):

Parameter Type Default Description
delay_seconds number 0 Deliver this many seconds after the task is created. Must be >= 0; fractions are allowed.
schedule_time string (RFC 3339) now Deliver at this instant, for example 2026-12-01T09:00:00Z. A time in the past makes the task due immediately.

Use delay_seconds for relative times (“in 3 days”) and schedule_time for wall-clock times (“Monday 09:00 in the user’s time zone”). schedule_time is an absolute instant: convert the user’s local time to UTC (or include the offset) in your code.

await pq.createTask("emails", {
taskId: "digest-user-42-2026-12-07",
path: "/hooks/weekly-digest",
jsonBody: { userId: 42 },
scheduleTime: new Date("2026-12-07T09:00:00-05:00"), // 09:00 New York time
});

A task can be scheduled at most one year ahead on a default self-hosted server (limits.max_schedule_ahead, or PUSHQ_MAX_SCHEDULE_AHEAD; see self-hosting configuration). The limit applies to both delay_seconds and schedule_time; going past it returns invalid_argument with “schedule_time is more than … ahead”. Independently of that setting, delay_seconds can never exceed 100 years.

For anything further out (a renewal reminder in two years), store the date in your own database and have a periodic job enqueue the task once it is within range.

Delete the task with DELETE /v1/queues/{queue}/tasks/{task_id}. What that does depends on where the task is:

Task state Effect of delete
pending (waiting for its time, or due) Removed. It is never delivered.
running (a request is in flight) Marked deleted and its result is discarded, so it won’t be retried. The request already sent can’t be recalled.
succeeded or failed The record is removed. Delivery already happened (or gave up).
Already deleted, or never existed 404 not_found.

To cancel every scheduled task for a user, give their tasks a shared prefix (followup-user-42, digest-user-42-2026-12-07, …) and delete the pending ones you find with id_prefix:

const page = await pq.listTasks("emails", { state: "pending", idPrefix: "digest-user-42-", pageSize: 1000 });
for (const t of page.items) await pq.deleteTask("emails", t.id);

If a user can have more than 1,000 pending tasks, follow next_page_token as shown in list and filter tasks.

pushq has no “update task” call. To move a task to a new time, delete it and create it again.

So give the new task a new ID. A version or the target time in the ID works well, and an id_prefix lookup still finds it:

// Move the follow-up from 3 days to 7 days after signup.
await pq.deleteTask("emails", "followup-user-42");
await pq.createTask("emails", {
taskId: "followup-user-42-v2",
path: "/hooks/follow-up",
jsonBody: { userId: 42 },
delaySeconds: 7 * 24 * 3600,
});

To cancel a rescheduled task later, look it up with id_prefix: "followup-user-42" rather than a fixed ID. Delete first, then create: if you create first and the delete fails, both versions are scheduled.

To move a pending task to now, use run a task now (POST .../tasks/{task_id}:run) instead. It keeps the same ID, works only on pending tasks, and bypasses the queue’s rate limit and paused state.

How scheduled tasks are stored and delivered

Section titled “How scheduled tasks are stored and delivered”

A scheduled task is an ordinary pending task whose schedule_time is in the future. Nothing runs on your side while it waits. pushq’s dispatcher tracks the earliest schedule_time of each queue and claims the task once that time has passed, subject to the queue’s rate limits. Queue stats count waiting tasks in scheduled_future, and each delivery carries the original time in the X-Pushq-Scheduled-Time header.

Some consequences:

  • Delivery is at or after schedule_time, not exactly at it. A busy queue, a low rate limit, or a paused queue makes tasks late. Tasks that become due while a queue is paused go out when it is resumed.
  • Retries move the time. If the first attempt fails, the task is retried with backoff (see retries), so the follow-up can arrive later than scheduled.
  • Scheduled tasks live in their queue. Deleting or purging the queue removes every scheduled task in it.
  • Random task IDs. Without a predictable ID you must store the returned ID to cancel the task later.
  • Reusing an ID right after delete. It fails with already_exists for the dedup window; use a new ID.
  • Local times without an offset. schedule_time must be an RFC 3339 instant. In Python a naive datetime is treated as UTC.
  • Relying on delete alone. Re-check in the handler that the action is still wanted.
  • Scheduling years ahead. Past the schedule-ahead limit the create fails; keep long-range dates in your own database.