Skip to Content

The run object

The run object schema for Realtime subscriptions

The run object is the main object returned by Realtime subscriptions (e.g., runs.subscribeToRun()). It contains all the information about the run, including the run ID, task identifier, payload, output, and more.

Type-safety is supported for the run object, so you can infer the types of the run's payload and output. See type-safety for more information.

The run object

Properties

idstringpathrequired

The run ID.

taskIdentifierstringpathrequired

The task identifier.

payloadobjectpathrequired

The input payload for the run.

outputobjectpath

The output result of the run.

createdAtDatepathrequired

Timestamp when the run was created.

updatedAtDatepathrequired

Timestamp when the run was last updated.

statusRunStatuspathrequired

Current status of the run.

StatusDescription
PENDING_VERSIONRun is waiting for a version update because it cannot execute without additional information
QUEUEDRun is waiting to be executed by a worker
DEQUEUEDRun has been dequeued and is being sent to a worker to start executing
EXECUTINGRun is currently being executed by a worker
WAITINGRun has been paused by the system, and will be resumed by the system
COMPLETEDRun has been completed successfully
CANCELEDRun has been canceled by the user
FAILEDRun has been completed with errors
CRASHEDRun has crashed and won't be retried, most likely the worker ran out of resources, e.g. memory or storage
SYSTEM_FAILURERun has failed to complete, due to an error in the system
DELAYEDRun has been scheduled to run at a specific time
EXPIREDRun has expired and won't be executed
TIMED_OUTRun has reached it's maxDuration and has been stopped
durationMsnumberpathrequired

Duration of the run in milliseconds.

costInCentsnumberpathrequired

Total cost of the run in cents.

baseCostInCentsnumberpathrequired

Base cost of the run in cents before any additional charges.

tagsstring[]pathrequired

Array of tags associated with the run.

idempotencyKeystringpath

Key used to ensure idempotent execution.

expiredAtDatepath

Timestamp when the run expired.

finishedAtDatepath

Timestamp when the run finished.

startedAtDatepath

Timestamp when the run started.

delayedUntilDatepath

Timestamp until which the run is delayed.

queuedAtDatepath

Timestamp when the run was queued.

metadataRecord<string, DeserializedJson>path

Additional metadata associated with the run.

errorSerializedErrorpath

Error information if the run failed.

isTestbooleanpathrequired

Indicates whether this is a test run.

realtimeStreamsstring[]pathrequired

Names of the Realtime streams on the run.

isQueuedbooleanpathrequired

true if the run is queued, delayed or waiting for a version update.

isExecutingbooleanpathrequired

true if the run is dequeued or executing.

isWaitingbooleanpathrequired

true if the run is waiting.

isCompletedbooleanpathrequired

true if the run has finished, either successfully or with any failure status.

isFailedbooleanpathrequired

true if the run failed, crashed, hit a system failure, expired or timed out.

isSuccessbooleanpathrequired

true if the run completed successfully.

isCancelledbooleanpathrequired

true if the run was canceled.

Type-safety

You can infer the types of the run's payload and output by passing the type of the task to the subscribeToRun function. This will give you type-safe access to the run's payload and output.

import { ,  } from "@trigger.dev/sdk";
import type {  } from "./trigger/my-task";

// Somewhere in your backend code
async function myBackend() {
  const handle = await .trigger("my-task", { some: "data" });

  for await (const run of .subscribeToRun<typeof >(handle.id)) {
    // This will log the run every time it changes
    .(run.payload.some);

    if (run.output) {
      // This will log the output if it exists
      .(run.output.some);
    }
  }
}

When using subscribeToRunsWithTag, you can pass a union of task types for all the possible tasks that can have the tag.

import {  } from "@trigger.dev/sdk";
import type { ,  } from "./trigger/my-task";

// Somewhere in your backend code
for await (const run of .subscribeToRunsWithTag<typeof  | typeof >("my-tag")) {
  // You can narrow down the type based on the taskIdentifier
  switch (run.taskIdentifier) {
    case "my-task": {
      .("Run output:", run.output.foo); // This will be type-safe
      break;
    }
    case "my-other-task": {
      .("Run output:", run.output.bar); // This will be type-safe
      break;
    }
  }
}

This works with all realtime subscription functions:

  • runs.subscribeToRun<TaskType>()
  • runs.subscribeToRunsWithTag<TaskType>()
  • runs.subscribeToBatch<TaskType>()

Was this page helpful?

Last updated

Edit on GitHub

On this page