Changelog #41

·

Run Notifications

Eric Allam

Eric Allam

CTO, Trigger.dev

Image for Run Notifications

Before today, it was a very clunky experience trying to build workflows that responded to your job runs completing or failing. But now, you can easily subscribe to run notifications and perform additional work.

There are two ways of subscribing to run notifications:

Across all jobs

You can use the TriggerClient.on instance method to subscribe to all job runs notifications. This is useful if you want to perform some work after any job run completes or fails:


_12
export const client = new TriggerClient({
_12
id: "my-project",
_12
apiKey: process.env.TRIGGER_API_KEY,
_12
});
_12
_12
client.on("runSucceeeded", async (notification) => {
_12
console.log(`Run on job ${notification.job.id} succeeded`);
_12
});
_12
_12
client.on("runFailed", async (notification) => {
_12
console.log(`Run on job ${notification.job.id} failed`);
_12
});

On a specific job

You can also pass onSuccess or onFailure when defining a job to subscribe to notifications for that specific job:


_19
client.defineJob({
_19
id: "github-integration-on-issue",
_19
name: "GitHub Integration - On Issue",
_19
version: "0.1.0",
_19
trigger: github.triggers.repo({
_19
event: events.onIssue,
_19
owner: "triggerdotdev",
_19
repo: "empty",
_19
}),
_19
onSuccess: async (notification) => {
_19
console.log("Job succeeded", notification);
_19
},
_19
onFailure: async (notification) => {
_19
console.log("Job failed", notification);
_19
},
_19
run: async (payload, io, ctx) => {
_19
// ...
_19
},
_19
});

Run notifications

All run notifications contain the following info:

  • The run's ID
  • The run's status
  • The run's duration
  • The run's start time
  • The run's payload
  • The run's explicit statuses (if any)
  • Whether or not the run was a test run
  • Which job the run belongs to
  • Which environment the run belongs to
  • Which project the run belongs to
  • Which organization the run belongs to
  • The external account associated with the run (if any)

Successful run notifications also contain the output of the run. Failed run notifications contain the error and the task that failed.

You can see the full run notification schema here

How does it work?

Run notifications work by making a separate HTTP request to your endpoint URL after a run completes or fails, which means that you get a fresh serverless function execution to perform additional work.

We only send these notifications if you've subscribed to them, so ff you want to stop receiving them, just remove the code that subscribes to them, and we'll stop sending them.

How to update

The Trigger.dev Cloud is now running v2.2.10. If you are self-hosting you can upgrade by pinning to the v2.2.10 tag.

The trigger.dev/* packages are now at v2.2.7. You can update using the following command:


_10
npx @trigger.dev/cli@latest update

Ready to start building?

Build and deploy your first task in 3 minutes.

Get started now
,