<@ULVA73B9P> I am using DeploymentTrigger for trig...
# ask-marvin
a
@Marvin I am using DeploymentTrigger for triggering a deployment run with below settings. Is it possible that my deployment run is triggered when all three dataset_* events are received. Currently if one of the specified event is received the deployment gets triggered. I wanted deployment to be triggered only once all events are received.
DeploymentEventTrigger(
expect=["dataset_a","dataset_b","dataset_c"],
match= {
"prefect.resource.id": ["etl-events.transform"]
}
)
m
thought for 238.0 seconds
Yes. A single
DeploymentEventTrigger
treats multiple
expect
values as OR. To get AND semantics (only trigger after all three events have occurred), wrap three event triggers in a
DeploymentCompoundTrigger
with
require="all"
. Example (Prefect 3.x), order does not matter and all three must arrive within 1 hour:
Copy code
from datetime import timedelta
from prefect import flow
from prefect.events.schemas.deployment_triggers import DeploymentCompoundTrigger

@flow
def my_flow():
    ...

my_flow.serve(
    name="process-all-datasets",
    triggers=[
        DeploymentCompoundTrigger(
            require="all",
            within=timedelta(hours=1),  # optional time window
            triggers=[
                {
                    "type": "event",
                    "expect": ["dataset_a"],
                    "match": {"prefect.resource.id": "etl-events.transform"},
                },
                {
                    "type": "event",
                    "expect": ["dataset_b"],
                    "match": {"prefect.resource.id": "etl-events.transform"},
                },
                {
                    "type": "event",
                    "expect": ["dataset_c"],
                    "match": {"prefect.resource.id": "etl-events.transform"},
                },
            ],
        )
    ],
)
Notes: - Duplicates of the same event won’t prematurely fire the compound trigger; each child trigger must fire at least once. - Add
within
to ensure all three events occur in a bounded window; otherwise older events can accumulate indefinitely. - If order matters, use a
DeploymentSequenceTrigger
instead of a compound trigger. Docs: - Event triggers (concepts) - Automations (concepts) - DeploymentCompoundTrigger API Follow-up questions: - Do these events need to arrive in a specific order? - Do you want a specific time window (e.g., all three within N minutes/hours) to avoid stale events triggering later?