<@ULVA73B9P> how do I trigger a flow run from a de...
# ask-marvin
c
@Marvin how do I trigger a flow run from a deployment when a previous run from the same deployment is completed?
m
To trigger a flow run from a deployment when a previous run from the same deployment is completed in Prefect, you can use event triggers. Here’s a step-by-step guide: 1. Define an Automation: Use Prefect Automations to set an event-based trigger. 2. Set the Condition: The condition should be the completion of a flow run from the specific deployment. 3. Configure the Triggering Action: The action to be taken when the event is detected (i.e., triggering the next flow run). Here's a snippet to illustrate the concept: 1. Create a Deployment:
Copy code
python
   from prefect import flow
   
   @flow(name="my_flow")
   def my_flow():
       # Add your flow code here
       pass

   # Command to create a deployment
   `prefect deployment build my_flow.py:my_flow -n my-deployment`
2. Use Prefect Automations: Prefect Cloud provides the feature to set up automations, which can trigger actions based on specific events. 3. Define Event Triggers and Conditions on Completion: Navigate to the Automations section in Prefect Cloud, and set a condition for the flow run completion event, then define the next flow run trigger as the action. For detailed examples and further configuration, refer to the Prefect documentation on Automations. ### Links for Reference: - Automations in Prefect - Building and managing Deployments If you need further customization or specific configurations, feel free to explore these links.
c
how to make this work with self-hosted server?
n
hi @Christine Chen! we actually open-sourced events, but theres a straightforward way to do it if you dont want to use a Deployment trigger, which is to schedule another run from the deployment in an
on_completion
hook with
run_deployment
you'll want to use
timeout=0
with run_deployment so you dont block your flow from completing until the one you trigger completes --- if you did want to try out events to do pretty much the same thing, you could define a trigger for your flow like this
Copy code
- name: triggered-event
  entrypoint: triggered_by_event.py:event_triggered_flow
  work_pool:
    name: local
  triggers:
    - enabled: true
      match_related:
        prefect.resource.name: your_flow_name
      expect:
        - prefect.flow-run.Completed
🙏 1
c
Thanks @Nate! This looks like what I was looking for.