Integrations

Any Integrations that you added in the integrations param of the Job constructor will be available on the io object in the run() function with the same name as the key. For example:

View the Integrations documentation for information on how to use Integrations.

Properties

logger

Used to send log messages to the Run log.

store

Exposes namespaced Key-Value Stores you can access inside of your Jobs.

Instance methods

runTask()

io.runTask() allows you to run a Task from inside a Job run. A Task is a resumable unit of a Run that can be retried, resumed and is logged. Integrations use Tasks internally to perform their actions.

sendEvent()

io.sendEvent() allows you to send an event from inside a Job run. The sent even will trigger any Jobs that are listening for that event (based on the name).

If you want to send an event from outside a run (e.g. just from your backend) you can use client.sendEvent().

wait()

Waits for a certain amount of time before continuing the Job. Delays works even if you’re on a serverless platform with timeouts, or if your server goes down. They utilize resumability to ensure that the Run can be resumed after the delay.

waitForEvent()

io.waitForEvent() allows you to pause the execution of a run until an event is received, and receive the event data.

waitForRequest()

io.waitForRequest() allows you to pause the execution of a run until the provided URL is requested, and receive the request data.

sendEvents()

io.sendEvents() allows you to send multiple events from inside a Job run. The sent events will trigger any Jobs that are listening for those events (based on the name).

If you want to send multiple events from outside a run (e.g. just from your backend) you can use client.sendEvents().

backgroundFetch()

io.backgroundFetch() allows you to fetch data from a URL that can take longer that the serverless timeout. The actual fetch request is performed on the Trigger.dev platform, and the response is sent back to you. An example use case is fetching data from a slow API, like some AI endpoints.

backgroundPoll()

io.backgroundPoll() allows you to fetch data from a URL on an interval, in the background.

random()

io.random() is identical to Math.random() when called without options but ensures your random numbers are not regenerated on resume or retry. It will return a pseudo-random floating-point number between optional min (default: 0, inclusive) and max (default: 1, exclusive). Can optionally round to the nearest integer.

try()

io.try() allows you to run Tasks and catch any errors that are thrown, it’s similar to a normal try/catch block but works with io.runTask().

registerInterval()

io.registerInterval() allows you to register a DynamicSchedule that will run on a regular interval.

unregisterInterval()

io.unregisterInterval() allows you to unregister a DynamicSchedule that was previously registered with io.registerInterval().

registerCron()

io.registerCron() allows you to register a DynamicSchedule that will run on a regular cron schedule.

unregisterCron()

io.unregisterCron() allows you to unregister a DynamicSchedule that was previously registered with io.registerCron().

registerTrigger()

io.registerTrigger() allows you to register a DynamicTrigger with the specified trigger data.

yield()

io.yield() allows you to yield the current run and resume it immediately in a different function execution context. Requires a single argument that defines the yield key which works similar to task keys.

brb()

io.brb() is is alias for io.yield().