Tasks

Background functions triggered via fan-out, programmatic triggers, or the dashboard. Unlike crons, tasks have no schedule — they run on demand.

Quick Example

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

export const sendEmail = task("send-email", async (ctx) => {
  const { to, subject, body } = ctx.payload as {
    to: string;
    subject: string;
    body: string;
  };

  ctx.log(`Sending email to ${to}`);
  await emailClient.send({ to, subject, body });
}, { retries: 3, timeout: "30s" });

Registration

ParameterTypeRequiredDescription
namestringYesUnique identifier for this task.
handlerfunctionYesFunction to execute. Receives context and payload.
optionsobjectNoConfiguration (see below).

Options

OptionTypeDefaultDescription
retries0–100Retry attempts with exponential backoff.
timeoutstring"30s"Max execution time.
concurrency1–101Max concurrent executions.

Payload

Tasks receive a payload — arbitrary JSON data passed when the task is triggered. The payload is available via the context object. SDKs may support typed payloads for automatic deserialization.

Execution Lifecycle

  1. A task is triggered (via fan-out, trigger(), or dashboard).
  2. A pending execution is created with the payload.
  3. The execution is dispatched to the job queue.
  4. Your handler runs with the context and payload.
  5. On failure, retried with exponential backoff if retries > 0.