We use cookies

We use cookies to ensure you get the best experience on our website. For more information on how we use cookies, please see our cookie policy.

By clicking "Accept", you agree to our use of cookies.
Learn more.

User GuideEvent Trigger

Run on Event

This example assumes we have a workflow registered on a running worker.

Run-on-event allows you to trigger one or more workflows when a specific event occurs. This is useful when you need to execute a workflow in response to an ephemeral event where the result is not important. A few common use cases for event-triggered workflow runs are:

  1. Running a workflow when an ephemeral event is received, such as a webhook or a message from a queue.
  2. When you want to run multiple independent workflows in response to a single event. For instance, if you wanted to run a send_welcome_email workflow, and you also wanted to run a grant_new_user_credits workflow, and a reward_referral workflow, all triggered by the signup. In this case, you might declare all three of those workflows with an event trigger for user:signup, and then have them all kick off when that event happens.
⚠️

Event triggers evaluate workflows to run at the time of the event. If an event is received before the workflow is registered, the workflow will not be run.

Declaring Event Triggers

To run a workflow on an event, you need to declare the event that will trigger the workflow. This is done by declaring the on_events property in the workflow declaration.

Note: Multiple workflows can be triggered by the same event.

Pushing an Event

You can push an event to the event queue by calling the push method on the Hatchet event client and providing the event name and payload.