GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing trigger.dev — Runs - Trigger.dev In Trigger.dev, the concepts of runs and attempts are fundamental to understanding how tasks are executed and managed. This article explains these concepts in detail and provides insights into the various states a run can go through during its lifecycle.
What are runs?A run is created when you trigger a task (e.g. callingyourTask.trigger({ foo: "bar" })). It represents a single instance of a task being executed and contains the following key information:
The run lifecycleA run can go through various states during its lifecycle. The following diagram illustrates a typical state transition where a single run is triggered and completes successfully:
Runs can also find themselves in lots of other states depending on what’s happening at any given time. The following sections describe all the possible states in more detail.
Initial statesPending version: The task is waiting for a version update because it cannot execute without additional information (task, queue, etc.). Delayed: When a run is triggered with a delay, it enters this state until the specified delay period has passed. Queued: The run is ready to be executed and is waiting in the queue. Dequeued: The task has been dequeued and is being sent to a worker to start executing.Execution statesExecuting: The task is currently being executed by a worker. Waiting: You have used a triggerAndWait(), batchTriggerAndWait() or a wait function. When the wait is complete, the task will resume execution.Final statesCompleted: The task has successfully finished execution. Canceled: The run was manually canceled by the user. Failed: The task has failed to complete successfully due to an error in the task code. Timed out: Task has failed because it exceeded itsmaxDuration.
Crashed: The worker process crashed
during execution (likely due to an Out of Memory error) and won’t be retried, unless retry.outOfMemory.machine is set to retry on a larger machine. See Machines.
System failure: An unrecoverable system
error has occurred.
Expired: The run’s Time-to-Live
(TTL) has passed before it could start executing.
AttemptsAn attempt represents a single execution of a task within a run. A run can have one or more attempts, depending on the task’s retry settings and whether it fails. Each attempt has:
Run completionA run is considered finished when:
Boolean helpersRun objects returned from the API and Realtime include convenient boolean helper methods to check the run’s status:
Advanced run featuresIdempotency KeysWhen triggering a task, you can provide an idempotency key to ensure the task is executed only once, even if triggered multiple times. This is useful for preventing duplicate executions in distributed systems.
Canceling runsYou can cancel an in-progress run using the API or the dashboard:Time-to-live (TTL)TTL is a time-to-live setting that defines the maximum duration a run can remain in a queued state before being automatically expired. You can set a TTL at three levels, with the following precedence:
trigger.config.ts ttl: 0:
ttl: 0 on the task definition:
Setting ttl: 0 removes the config-level or task-level TTL, but the platform-level maximum still applies. See Limits - Maximum run TTL for details.Expired. This is useful for time-sensitive tasks where immediate execution is important. For example, when you queue many runs simultaneously and exceed your concurrency limits, some runs might be delayed - using TTL ensures they only execute if they can start within your specified timeframe.
Dev runs automatically have a 10-minute TTL. On Trigger.dev Cloud, staging and production runs have a maximum TTL of 14 days applied automatically (runs without an explicit TTL get 14 days; longer TTLs are clamped). See Limits — Maximum run TTL for details.
Delayed runsYou can schedule a run to start after a specified delay:
Replaying runsYou can create a new run with the same payload as a previous run:Waiting for runstriggerAndWait()ThetriggerAndWait() function triggers a task and then lets you wait for the result before continuing. Learn more about triggerAndWait().
batchTriggerAndWait()Similar totriggerAndWait(), the batchTriggerAndWait() function lets you batch trigger a task and wait for all the results Learn more about batchTriggerAndWait().
Runs APIruns.list()runs.list() is for browsing, reporting, and bulk operations, not for coordinating runs. Don’t
call it before every trigger or poll it in a loop. See runs.list() best
practices for what to use instead.list() function to narrow down the results:
runs.retrieve()Fetch a single run by it’s ID:run.payload and run.output:
retrieve() and the response will already be typed:
runs.cancel()Cancel a run:runs.replay()Replay a run, optionally overriding its payload or options for the new run:runs.reschedule()Updates a delayed run with a new delay. Only valid when the run is in the DELAYED state.Real-time updatesSubscribe to changes to a specific run in real-time:runs.retrieve(), you can provide the type of the task to correctly type the run.payload and run.output:
Triggering runs for undeployed tasksIt’s possible to trigger a run for a task that hasn’t been deployed yet. The run will enter the “Pending version” state until the task is deployed. Once deployed, the run will be queued and executed normally. This feature is particularly useful in CI/CD pipelines where you want to trigger tasks before the deployment is complete.Was this page helpful? ⌘I |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |