Context Object

Every handler receives a context object with execution metadata, logging, and task dispatch.

Quick Example

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

export const syncData = task("sync-data", async (ctx) => {
  ctx.log("Starting sync", { attempt: ctx.attempt, scheduledAt: ctx.scheduledAt });

  try {
    const result = await fetchExternalData(ctx.payload.source);
    ctx.log(`Fetched ${result.count} records`);
    await saveToDatabase(result.data);
  } catch (err) {
    ctx.log.error("Sync failed", { error: String(err) });
    throw err; // rethrow to trigger retry
  }
});

Properties

PropertyTypeDescription
executionIdstringUnique UUID for this execution.
attemptnumberCurrent retry attempt (1-indexed). First run is attempt 1.
scheduledAtDate/datetimeWhen this execution was originally scheduled.
payloadanyThe payload passed when the task was triggered (tasks only).

Methods

log(message, meta?)

Add a structured log entry at the info level. All log entries are captured and returned to the platform, visible in the dashboard.

log.warn(message, meta?) / log.error(message, meta?) / log.debug(message, meta?)

Log at warning, error, or debug level respectively.

LevelUse for
infoNormal operations, progress updates
warnUnexpected but recoverable conditions
errorFailures that affect the result
debugVerbose information for troubleshooting

task(name, payload)

Dispatch a child task for fan-out. The task is collected and dispatched after the handler completes. See Fan-Out for details.

ParameterTypeDescription
namestringName of a registered task.
payloadanyJSON-serializable data passed to the child task.