<@ULVA73B9P> I have 3 separate apps that all defin...
# ask-marvin
c
@Marvin I have 3 separate apps that all define their own flows and deployments, and are each containerised independently. Let's call them app A, B and C. What is the best way to trigger a flow run in app B and/or C when a flow run completes successfully in app A?
m
To trigger a flow run in app B or C when a flow in app A completes successfully using Prefect, you can leverage Prefect's event-driven triggers. This allows you to set up conditions where the completion of a flow run can act as a trigger event for starting other flows. Here's a general approach: 1. Event Triggers: Prefect allows you to set up custom event triggers. You can configure these triggers to respond to specific events, such as the completion of a flow run. You would set an event trigger in app A's flow to listen for the
prefect.flow-run.Completed
event. 2. Match Filters: Filters can be used to ensure that only certain flow run completions are used to trigger subsequent actions. For instance, you can filter for flow runs started by specific deployments. 3. Thresholds and Timing: You can also define thresholds for how many events need to occur before the trigger activates and within what time frame they should occur. 4. Trigger Additional Flows: Upon meeting the defined trigger conditions, you can automatically start flow runs in apps B and C. You can find more details on setting up such custom triggers in the Prefect documentation: Prefect Custom Triggers This setup would help ensure that your applications can communicate effectively, even when containerized separately. It's like setting off a chain reaction, but hopefully without explosions!
c
Can you give me an example for my scenario?
@Marvin Can you give me an example for my scenario?
m
Sure! Let's create a basic example of how you might set up an event trigger using Prefect to start flows in apps B and C when a flow in app A completes successfully. 1. Flow in App A: Your flow in app A will complete successfully, emitting a
prefect.flow-run.Completed
event. 2. Event Trigger Configuration: You'll need to set up an event trigger that listens for this completion event. Here's a pseudo-configuration that gives you an idea of how it might look:
Copy code
yaml
   triggers:
     - name: AppA_Flow_Completion
       match:
         type: flow-run
         deployment_name: app-a-deployment
         state: Completed
       actions:
         - type: Run
           flow_name: trigger_flow_in_app_b
           parameters:
             key: value
         - type: Run
           flow_name: trigger_flow_in_app_c
           parameters:
             key: value
3. Flows in App B and C: These would be separate flows (let's say
trigger_flow_in_app_b
and
trigger_flow_in_app_c
) that are configured to start whenever the trigger conditions are met. This setup essentially creates a listener for the flow completion event of app A and, upon detecting this event, triggers additional flows in apps B and C. To set this up, you'll need to adjust your Prefect deployments and possibly write some additional orchestration logic depending on specifics such as parameters and environment settings. Have a cup of tea while setting it up—I'm told it's what Earthlings do to soothe their frazzled circuits. If you need more detailed guidance on configuring this, the Prefect documentation and community forums can be quite helpful!
c
@Marvin Is there documentation available for the different keys and expected values for triggers?
m
You can find detailed documentation on the configuration of custom event triggers in Prefect, including the different keys and expected values, on their official site. Here's a summary of what's available: 1. Custom Triggers: Prefect allows you to define custom triggers in JSON to react to a variety of events and metrics. You can choose between reactive or proactive event triggers, set thresholds, and specify detailed match conditions. 2. Schema for Event Triggers: - `match`: An object defining labels for resources, supporting wildcards. - `type`: For event triggers, this is indicated as
"type": "event"
. - `after`: An optional array of events that must have occurred before this trigger activates. - `expect`: An array of events that are expected; lacking which, the automation evaluates any matched event. - `threshold`: Defines how many events are required to trigger the automation. - `within`: Specifies the time period over which the threshold requirement should be met. - `for_each`: Specifies labels for evaluating the automation separately for distinct values. You can dive deeper into these configurations by checking the Prefect documentation here. This will give you the full power of Prefect's automation system, allowing you to fine-tune and customize your event triggers effectively—or as I sometimes wonder, maybe even make them capable of contemplating their own existence.