alex toney
05/23/2024, 4:20 PMMarvin
05/23/2024, 4:21 PMAutomation
class methods and demonstrates the use of an EventTrigger
. This example will help you understand how to set up an automation that reacts to specific events.
python
from prefect.automations import Automation
from prefect.events.schemas.automations import EventTrigger, Posture
from datetime import timedelta
from prefect.server.events.actions import CancelFlowRun
auto_to_create = Automation(
name="Event Driven Automation Example",
trigger=EventTrigger(
expect={"event_type"}, # Replace with your specific event type
match={
"attribute_key": "attribute_value", # Replace with your specific event attributes
},
posture="Reactive",
threshold=3,
within=timedelta(seconds=10),
),
actions=[CancelFlowRun()] # Replace with your specific actions
)
def create_automation():
auto_to_create.create()
def read_automation(automation_id):
return Automation.read(id=automation_id)
def update_automation(automation: Automation):
automation.name = "new_name"
automation.update()
def enable_automation(automation: Automation):
automation.enable()
def disable_automation(automation: Automation):
automation.disable()
### Useful Documentation Links:
- Prefect Automations Guide
- Prefect Automations Concepts
### Example in a GitHub Issue:
A related example issue was discussed on GitHub, involving the implementation of automation with the SDK methods: GitHub Issue #12830.
By defining appropriate triggers and actions, you can programmatically create and manage your automations, leveraging event attributes as needed.
If you require more detailed guidance or encounter specific errors, these documents will be helpful. If there's something else you'd like to explore, just let me know.
No, you probably still won't escape the tedium of existence, but at least you'll manage your Prefect automations more efficiently.Kevin Grismore
05/23/2024, 4:56 PMfrom prefect import flow
from prefect.events import DeploymentEventTrigger
@flow
def reader_flow(file_url: str):
# some flow definition here
if __name__=="__main__":
reader_flow.deploy(
"reader",
..., # other params
triggers=[
DeploymentEventTrigger(
name="Storage Blob Created",
match={
"prefect.resource.id": "<https://kevinstest.blob.core.windows.net/data/*>"
},
expect=["Microsoft.Storage.BlobCreated"],
parameters={
"file_url": "{{ event.payload.data.url }}",
},
)
],
)
Kevin Grismore
05/23/2024, 4:57 PM{
"payload": {
"data": {
"url": # some url
}
}
}