<@ULVA73B9P> How could I use Automations to trigge...
# ask-marvin
j
@Marvin How could I use Automations to trigger a run of a second deployment on the successful conclusion of a first deployment. The events associated with the conclusion of the deployment execution relate to flows and flow runs but both deployments share flow code (using different parameters to execute different processes) so the deployment is the unique trigger and target in each case.
m
Based on the information from Prefect's documentation, to trigger a run of a second deployment following the successful conclusion of the first deployment, you would need to use Automations within Prefect Cloud. Automations allow you to configure actions that automatically occur based on trigger conditions related to your flows and deployments. To accomplish this, you can set up deployment triggers in Prefect Cloud. Deployment triggers can be specified within a deployment to run based on the presence or absence of events. For example, you can configure the second deployment to be triggered upon the successful completion of a flow run associated with the first deployment. The trigger configuration would involve specifying conditions such as the completion of a particular flow run and could pass event data into the second deployment run as parameters using Jinja templating. Here is an excerpt from the documentation that describes how you might set up such a trigger:
Copy code
yaml
triggers:
  - enabled: true
    match:
      prefect.resource.id: prefect.flow-run.*
    expect:
      - prefect.flow-run.Completed
    match_related:
      prefect.resource.name: prefect.flow.etl-flow
      prefect.resource.role: flow
    parameters:
      param_1: "{{ event }}"
In this example, the trigger is enabled, and it is looking for a completed flow run (
prefect.flow-run.Completed
) that is related to the specific flow resource by name and role. When this condition is met, the trigger initiates the subsequent deployment. Please note that the specifics of how to configure the trigger could vary depending on the properties of the flow runs and the exact way you want to set up the triggering mechanism. It might involve details such as resource IDs, names, roles, and how to pass parameters. Keep in mind that Automations and detailed trigger specifications as mentioned are available only in Prefect Cloud. If you have further specific questions about the setup or execution, feel free to ask!
j
@Marvin The flow is invoked by multiple deployments so it is not sufficient to look for a completed flow run associated with a specific flow. Can I associate the match_related values with a specific deployment and, if so, what does that syntax look like? In addition, elaborate on how the parameters values might be employed for matching.
m
Yes, you can associate
match_related
values with a specific deployment in Prefect Automations. To do so, you should include the deployment's ID as part of the
match_related
condition. Here's an example of what the syntax might look like when matching on specific deployments:
Copy code
yaml
"match_related": {
  "prefect.resource.id": [
    "prefect.deployment.70cb25fe-e33d-4f96-b1bc-74aa4e50b761",
    "prefect.deployment.c33b8eaa-1ba7-43c4-ac43-7904a9550611"
  ],
  "prefect.resource.role": "deployment"
}
This configuration is used to match events related to particular deployments, as identified by their respective deployment IDs. Each key in
match
and
match_related
can accept a list of multiple values that are OR'd together, meaning the trigger will activate if any of the specified conditions are met. Regarding the use of parameters for matching, it seems that parameters can be employed to pass event data into the subsequent action or deployment run, potentially for further decision-making or processing. For instance, parameters could be used to customize the behavior of the triggered deployment based on the attributes of the triggering event. Here's an excerpt of syntax that shows how parameters might be specified using the event data:
Copy code
yaml
parameters: {
  param_1: "{{ event }}"
}
In this case,
param_1
is a parameter for the deployment action, and
{{ event }}
represents the data from the triggering event that you would use within your deployment. The exact structure of the event and how its data is mapped to the parameters would depend on the specifics of the Automations being set up. Please remember that these features are available only within Prefect Cloud, and the implementation details would vary based on your deployments and workflows. If you need more concrete examples or further assistance with setting up these Automations, I recommend referring to the official Prefect documentation or seeking assistance from their support community.