Event Trigger
This example assumes we have a task registered on a running worker.
Run-on-event allows you to trigger one or more tasks when a specific event occurs. This is useful when you need to execute a task in response to an ephemeral event where the result is not important. See Event-Driven Systems for a detailed guide. A few common use cases for event-triggered task runs are:
- Running a task when an ephemeral event is received, such as a webhook or a message from a queue.
- When you want to run multiple independent tasks in response to a single event. For instance, if you wanted to run a
send_welcome_emailtask, and you also wanted to run agrant_new_user_creditstask, and areward_referraltask, all triggered by the signup. In this case, you might declare all three of those tasks with an event trigger foruser:signup, and then have them all kick off when that event happens.
Event triggers evaluate tasks to run at the time of the event. If an event is received before the task is registered, the task will not be run.
Declaring Event Triggers
To run a task on an event, you need to declare the event that will trigger the task. This is done by declaring the on_events property in the task declaration.
Note: Multiple tasks can be triggered by the same event.
As of engine version 0.65.0, Hatchet supports wildcard event triggers using
the * wildcard pattern. For example, you could register subscription:* as
your event key, which would match incoming events like subcription:create,
subscription:renew, subscription:cancel, and so on.