Sean Conroy
11/30/2022, 9:34 PMis_successful()
method from Prefect 1 for Prefect 2?
In other words, is testing the state name = 'Completed' the best way to check for success?
myflow_state = my_flow(return_state=True)
# Test if state is successfull:
if not myflow_state.name == 'Completed':
raise Exception("myflow failed")
Bianca Hoch
11/30/2022, 9:41 PMfrom prefect import task, flow
from prefect.blocks.notifications import SlackWebhook
from prefect.orion.schemas.states import StateType
#Load your desired block, this example uses a slack notification block.
def notify_function():
slack_webhook_block = SlackWebhook.load("my-test-notification")
#This is the message you want to send to slack
slack_webhook_block.notify("Hello from Prefect!")
#A simple flow
@flow
def my_flow():
pass
if __name__ == "__main__":
#Store the state of your flow
state = my_flow(return_state=True)
'''This if statement checks for a specific flow state.
If the condition is satisfied, the block is envoked.
State type can be set to any available state type: <https://docs.prefect.io/concepts/states/#state-types''>'
if state.type == (StateType.COMPLETED):
notify_function()
Sean Conroy
11/30/2022, 9:50 PM