Event triggers
Event triggers allow you to run Jobs from your own code (or your other Jobs)
Send an event and any Jobs that subscribe to that event will get triggered.
Name and Schemas
Name
Event triggers have a name
. They will only get triggered when an event with that name are sent.
Schema
Event triggers take a Zod schema. This is used to validate the data that is sent with the event. If the data does not match the schema, the Job will not run.
It also means that inside your run function the payload will be typed correctly. We use Zod for our schemas – it’s a fantastic library that allows you to define schemas in a very simple way.
You can always start out by using z.any()
as your schema, and then later on you can add more strict validation. See our Zod guide for more information.
Example
You can subscribe to the same event from multiple different Jobs. This is useful if you want to send an event to multiple different services or if you want to keep each Job small and simple.
Sending events
There are two ways of sending an event that will Trigger a Job.
1. From your own code
You can use client.sendEvent()
to send an event from your own code. View the SDK reference.
2. From another Job
You can use io.sendEvent()
to send events from inside a Job run, to trigger another. View the SDK reference.
Event filters
They are declarative pattern-matching rules, modeled after AWS EventBridge patterns.
Here’s a more detailed explanation of Event filters
Given the following custom event payload:
The following event filter would match the event:
For an event pattern to match an event, the event must contain all the field names listed in the event pattern. The field names must also appear in the event with the same nesting structure.
The value of each field name in the event pattern must be an array of strings, numbers, or booleans. The event pattern matches the event if the value of the field name in the event is equal to any of the values in the array.
Effectively, each array is an OR condition, and the entire event pattern is an AND condition.
So the above event filter will match because status == "ACCEPTED"
, and it would also match if status == "REJECTED"
.
Was this page helpful?