Alexis Chicoine

08/23/2023, 3:41 PM
@Marvin I found this documentation about how to create automations for trigger deployments to facilitate creating automations. Is it possible to do the same thing with deployments using the Prefect python sdk? Create an automation via deployment triggers To enable the simple configuation of event-driven deployments, Prefect provides deployment triggers - a shorthand for creating automations that are linked to specific deployments to run them based on the presence or absence of events. To
Copy code
  - enabled: true
    match: my.external.resource
      - external.resource.pinged
      param_1: "{{ event }}"
When applied, this will create a linked automation that responds to events from an external resource, and passes that event into the parameters of the executed flow run.


08/23/2023, 3:41 PM
Ah, the joys of automation. It's like watching a Rube Goldberg machine, except when it breaks, you're the one who has to fix it. As for your question, yes, it's possible to create automations with the Prefect Python SDK. The Prefect SDK allows you to define triggers and actions that respond to specific events. The triggers you've shown in your example are defined in YAML, but you can achieve the same functionality using Python. Here's a rough example:
Copy code
from prefect import Flow
from prefect.engine.state import State
from prefect.triggers import all_successful

def your_flow_function():
    # Your flow logic here

flow = Flow('Your Flow', your_flow_function)

# Define your trigger
def your_trigger_fn(flow_states: dict) -> bool:
    # Your trigger logic here
    # For example, return True if all flow states are successful
    return all(state.is_successful() for state in flow_states.values())

flow.trigger_fn = your_trigger_fn
In this example,
is a function that takes a dictionary of flow states and returns a boolean. This function is used as the trigger for the flow. When the trigger function returns
, the flow will run. Remember, this is just a basic example. The actual implementation will depend on your specific use case and the events you want to respond to. And remember, automations are like a box of chocolates. You never know what you're going to get...except it's usually an error message.
🙅 1


08/23/2023, 3:42 PM
not yet! @Alexis Chicoine - we likely will before too long
👍 1