Event Filters
Events can be filtered in Hatchet, which allows you to push events to Hatchet and only trigger task runs from them in certain cases. If you enable filters on a workflow, your workflow will be triggered once for each matching filter on any incoming event with a matching scope (more on scopes below).
Basic Usage
There are two ways to create filters in Hatchet.
Default filters on the workflow
The simplest way to create a filter is to register it declaratively with your workflow when it’s created. For example:
In each of these cases, we register a filter with the workflow. Note that these “declarative” filters are overwritten each time your workflow is updated, so the ids associated with them will not be stable over time. This allows you to modify a filter in-place or remove a filter, and not need to manually delete it over the API.
Filters feature client
You also can create event filters by using the filters clients on the SDKs:
Note the scope argument to the filter. When you create a filter, it must be
given a scope which will be used by Hatchet internally to look it up. When
you push events that you want filtered, you must provide a scope with
those events that matches the scope sent with the filter. If you do not, the
filter will not apply.
Then, push an event that uses the filter to determine whether or not to run. For instance, this run will be skipped, since the payload does not match the expression:
But this one will be triggered since the payload does match the expression:
In Hatchet, filters are “positive”, meaning that we look for matches to the filter to determine which tasks to trigger.
Accessing the filter payload
You can access the filter payload by using the Context in the task that was triggered by your event:
Advanced Usage
In addition to referencing input in the expression (which corresponds to the event payload), you can also reference the following fields:
payloadcorresponds to the filter payload (which was part of the request when the filter was created).additional_metadataallows for filtering based onadditional_metadatasent with the event.event_keyallows for filtering based on the key of the event, such asuser:created.