<@ULVA73B9P> how can i trigger a deployment from t...
# marvin-ai
d
@Marvin how can i trigger a deployment from the completion status of a scheduled run, for instance, if my hourly scheduled run completes then another flow deployment starts
@Marvin how can i trigger a deployment from the completion status of a scheduled run, for instance, if my hourly scheduled run completes then another flow deployment starts
m
thought for 258.1 seconds
Great question — in Prefect 3.x the cleanest way to do this is with an Automation that listens for your hourly deployment’s flow runs entering Completed, then runs another deployment. High-level - Trigger: Event trigger on
prefect.flow-run.Completed
- Filter: Match flow-run events related to your specific “hourly” deployment (via
match_related
) - Action:
run-deployment
to start the next deployment Option A: Do it in the UI (Prefect Cloud / UI) 1. Go to Automations → New automation 2. Trigger - Type: When a flow run enters a state - State(s): Completed (add Failed too if you want it to trigger on failure) - Filter: Deployment → select your hourly deployment 3. Action - Type: Run a deployment - Select the downstream deployment to start 4. Save and enable Docs: - Automations overview - Creating automations (UI guide) - Event triggers Option B: Define as YAML and create via CLI 1) Find your deployment IDs (hourly and downstream)
Copy code
prefect deployment ls -o json
2) Create an automation.yaml
Copy code
name: "Run downstream when hourly completes"
description: "Starts the downstream deployment after the hourly deployment completes"
enabled: true

trigger:
  type: event
  posture: Reactive
  expect:
    - prefect.flow-run.Completed
  # Primary resource is the flow run; filter the related deployment
  match:
    prefect.resource.id: "prefect.flow-run.*"
  match_related:
    - prefect.resource.role: "deployment"
      prefect.resource.id: "prefect.deployment.<HOURLY_DEPLOYMENT_UUID>"

actions:
  - type: run-deployment
    source: selected
    deployment_id: "<DOWNSTREAM_DEPLOYMENT_UUID>"
    # optional:
    # parameters:
    #   upstream_run_id: "{{ event.resource.id }}"
    # schedule_after: 60  # delay 60s before starting
3) Apply it
Copy code
prefect automation create --from-file automation.yaml
Variations - Trigger on success or failure:
Copy code
expect:
  - prefect.flow-run.Completed
  - prefect.flow-run.Failed
- Delay the downstream start:
Copy code
actions:
  - type: run-deployment
    source: selected
    deployment_id: "<UUID>"
    schedule_after: 300  # 5 minutes
- Pass context to the downstream:
Copy code
parameters:
  upstream_flow_run_id: "{{ event.resource.id }}"
  upstream_state: "{{ event.resource.labels['prefect.state-name'] }}"
Notes - Event name for completion is exactly
prefect.flow-run.Completed
. - Filtering “by deployment” is best done using
match_related
with: -
prefect.resource.role: "deployment"
-
prefect.resource.id: "prefect.deployment.<UUID>"
- This works regardless of how the upstream run was scheduled (hourly cron, etc.). Would you like me to draft this automation for your exact deployments? If so, share: - The name/ID of your hourly deployment - The name/ID of the downstream deployment - Whether to run only on success or also on failure - Any parameters you want to pass through