Thomas van Riet
11/20/2024, 3:35 PMMarvin
11/20/2024, 3:36 PMprefect.flow-run.Completed event from the first flow.
- Configure a "sequence" trigger if you need a series of triggers, where the completion of the first flow triggers the start of watching for subsequent events.
More detailed guidance can be found in the Prefect 2.x documentation on automations.
2. For Prefect 3.x:
Prefect 3.x provides enhanced support for custom triggers. You can:
- Leverage a "compound" or "sequence" trigger that reacts to the completion of the first flow.
- Specify parameter values for new flow runs, ensuring they match the first flow's parameters, when triggering the next flow.
You can explore more about this setup in the Prefect 3.x documentation on custom triggers and writing flows.
By configuring such triggers, you can achieve automated flow chaining based on the completion events, ensuring parameters align across both flows. It’s like a relay race where your baton (parameters) safely gets passed along from one smart runner to another, ensuring a seamless handoff!Brock
11/20/2024, 3:45 PMfrom prefect import flow
from prefect.events import DeploymentEventTrigger
if __name__ == "__main__":
flow.from_source(
source="my-github-project.git",
entrypoint="ml/pipeline/flows/fit-model.py:training_flow",
).deploy(
name="mlops-train-model",
work_pool_name="my-pool1",
job_variables={"env": {"ENV1": "loves-to-code"},
"pip_packages": ["pandas", "requests"]},
tags=["prod"],
description="Pipeline to train a model and log metrics and parameters for a training job",
version="1.0.0",
triggers=[
DeploymentEventTrigger(
expect={"prefect.flow-run.Completed"},
match_related={"prefect.resource.name": "ml-datasets"}
)
]
)
The key part above is the DeploymentEventTrigger which looks for the completed state on a previous flow, called ml-datasets aboveThomas van Riet
11/20/2024, 3:50 PMdef flow_a(id:int)
def flow_b(id:int)
when flow_a enters state Completed i want to trigger flow_b using the same id:int
so the triggering of flow_b based on flow_a completing is fairly easy to do - but dynamically passing the arguments in the automation is trickyBrock
11/20/2024, 4:06 PM