Delayed Triggers

Schedule a task to run after a specified delay instead of immediately.

Quick Example

import { PingbackClient } from "@usepingback/next";

const pingback = new PingbackClient({ apiKey: process.env.PINGBACK_API_KEY });

// Send a follow-up email 2 hours after sign-up
await pingback.trigger("send-followup", { userId: "usr_123" }, { delay: "2h" });

// Schedule a reminder 1 day and 30 minutes from now
await pingback.trigger("send-reminder", { userId: "usr_123" }, { delay: "1d30m" });

How It Works

When a delay is provided in a trigger request:

  1. The delay is parsed into seconds (see formats below).
  2. scheduledAt is set to now + delay instead of now.
  3. The job is queued with a startAfter delay in PgBoss.
  4. The execution appears as "pending" in the dashboard until the delay expires.
  5. After the delay, the task is dispatched normally.

Delay Formats

FormatExampleSeconds
Integer900900
Seconds"30s"30
Minutes"15m"900
Hours"2h"7200
Days"1d"86400
Combined"1d2h30m"95400

Constraints

  • Maximum delay: 30 days (2,592,000 seconds). Requests exceeding this return 400 Bad Request.
  • Minimum delay: 1 second. Zero or negative values return 400 Bad Request.
  • Precision: Fractional seconds are floored to the nearest integer.

SDK Reference

SDKSyntax
Next.jspingback.trigger("task", payload, { delay: "15m" })
NestJSthis.pingback.trigger("task", payload, { delay: "15m" })
Gopb.Trigger(ctx, "task", payload, pingback.WithDelay("15m"))
Pythonpb.trigger("task", payload, delay="15m")