Usage
Get compute duration and cost from inside a run, or for a specific block of code.
Getting the run cost and duration
You can get the cost and duration of the current including retries of the same run.
In Trigger.dev cloud we do not include time between attempts, before your code executes, or waits towards the compute cost or duration.
Getting the run cost and duration from your backend
You can use runs.retrieve() to get a single run or runs.list() to get a list of runs. The response will include costInCents
baseCostInCents
and durationMs
fields.
Getting the cost and duration of a block of code
You can also wrap code with usage.measure
to get the cost and duration of that block of code:
This will work from inside the run
function, our lifecycle hooks (like onStart
, onFailure
, onSuccess
, etc.), or any function you’re calling from the run
function. It won’t work for code that’s not executed using Trigger.dev.