Tate Wilks
08/30/2024, 8:44 PMMarvin
08/30/2024, 8:44 PMTate Wilks
08/30/2024, 8:44 PMNate
08/30/2024, 8:54 PMTate Wilks
08/30/2024, 8:55 PMMarvin
08/30/2024, 8:55 PM"type": "event"
trigger with the "expect": ["prefect.flow-run.Completed"]
event.
2. Set Up a Sequence Trigger: To ensure that Flow B only starts after Flow A completes, you can combine this event trigger within a sequence.
Let me summarize the steps below:
1. Create an automation in Prefect's UI or API.
2. Configure the automation to listen for the Completed
event of Flow A.
3. Add actions within the automation to trigger Flow B when Flow A completes.
Here’s an example structure for setting up such an automation:
json
{
"type": "sequence",
"within": 7200,
"triggers": [
{
"type": "event",
"posture": "Reactive",
"expect": ["prefect.flow-run.Completed"],
"match_related": {
"prefect.resource.name": "flow-A-name",
"prefect.resource.role": "flow"
}
},
{
"type": "action",
"action": "trigger-flow-B",
"match_related": {
"prefect.resource.name": "flow-B-name",
"prefect.resource.role": "flow"
}
}
]
}
Make sure to replace "flow-A-name"
and "flow-B-name"
with the actual names of your flows.
For further details, you can dive into these documentations:
1. Automations in Prefect
2. Flow Documentation
Enjoy the delight of making flows work together without constant bickering!Nate
08/30/2024, 8:57 PMfrom prefect import flow, serve
from prefect.events import DeploymentEventTrigger
@flow
def upstream_flow():
print("upstream flow")
@flow
def downstream_flow():
print("downstream flow")
if __name__ == "__main__":
upstream_deployment = upstream_flow.to_deployment(name="upstream_deployment")
downstream_deployment = downstream_flow.to_deployment(
name="downstream_deployment",
triggers=[
DeploymentEventTrigger(
expect={"prefect.flow-run.Completed"},
match_related={"prefect.resource.name": "upstream_deployment"},
)
],
)
serve(upstream_deployment, downstream_deployment)
in the above example we use events to chain two deployments, downstream runs are triggered on Completed
events from upstream
but it sounds like you might have some extra logic to determine if downstream should run?Tate Wilks
08/30/2024, 9:02 PMTate Wilks
08/30/2024, 9:04 PMNate
08/30/2024, 9:04 PMCompleted
event from upstream_deployment
• AND any other custom event(s) (like data.refreshed
or email.received
) that you emit
• optionally I need to see these within
some timeframe
and so for the "any other events" you can call emit_event
from anywhere you have python, or curl
a webhook to get the event to prefect so the automations can fireNate
08/30/2024, 9:05 PMcompound
triggerNate
08/30/2024, 9:07 PMTate Wilks
08/30/2024, 9:17 PMTate Wilks
08/30/2024, 9:17 PMNate
08/30/2024, 9:27 PMrun_deployment
to trigger your downstream from an on_completion
hook in the upstream, that way you could add logic in that hook to ask if the pre-conditions for the downstream are met before trying to schedule a run