Events in Trigger.dev
Events are the primary way to trigger jobs in the Trigger.dev integration. This guide explains how to send events, handle them, and implement best practices for event-driven architecture.Event Structure
Events in Trigger.dev have two main components:- Event Name: A string identifier for the event (e.g.,
user.created) - Payload: The data associated with the event (e.g., user information)
Sending Events
The@repo/trigger package provides a helper function for sending events:
Error Handling
ThesendEvent function includes built-in error handling:
API Integration
The API app includes a route handler that allows external systems to send events:Event Naming Conventions
It’s recommended to use a consistent naming convention for events:- Use dot notation to organize events hierarchically
- Start with the entity, followed by the action
- Use lowercase letters and avoid special characters
user.createduser.updatedpayment.succeededemail.sentdocument.shared
Type Safety
For better type safety, define interfaces for your event payloads:Event Patterns
Event Broadcasting
Send the same event to multiple consumers:Event Chaining
One job can trigger another job by sending an event:Delayed Events
You can schedule events to be sent in the future:Testing Events
For testing, you can send events directly to the API endpoint:Monitoring Events
The Trigger.dev dashboard provides tools for monitoring events:- Event history
- Success and failure rates
- Event payloads
- Related job runs