io.runTask()
Creates and runs a Task inside a Run.
A Task is a cached unit of work in a Job Run that are logged to the Trigger.dev UI. You can use io.runTask()
to create and run a Task inside a Run.
Any interaction with an external service (database or API) should be wrapped in a Task. Failing to do so could result in repeated work when runs are resumed.
Parameters
Should be a stable and unique cache key inside the run()
. See
resumability for more information.
The callback that will be called when the Task is run, this is where your logic should go. The callback receives the Task and the IO as parameters.
The options of how you’d like to run and log the Task.
An optional callback that will be called when the Task fails. You can perform
logic in here and optionally return a custom error object. Returning an object with { retryAt: Date, error?: Error }
will retry the Task at the specified Date. You can also just return a new Error
object to throw a new error. Returning null
or undefined
will rethrow the original error. If you want to force retrying to be skipped, return { skipRetrying: true }
.
Returns
A Promise that resolves with the returned value of the callback.
If the remote callback feature options.callback
is enabled, the Promise will instead resolve with the body of the first request sent to task.callbackUrl
.