Meyy
05/01/2023, 6:01 PMMarvin
05/01/2023, 6:02 PMslack_notifier
function in combination with the on_failure
event handler. Here's a rough example:
python
from prefect import task, Flow
from prefect.utilities.notifications import slack_notifier
@task
def failing_task():
raise ValueError("This task is designed to fail.")
@slack_notifier.on_failure
def notify_slack(task, state, **kwargs):
# Your code to send a message to Slack goes here.
# You can use the `state` parameter to get information about the failed task.
pass
with Flow("Slack_Notification_Example") as flow:
task_1 = failing_task()
task_1.set_task_run_states_handlers([notify_slack])
flow.run()
In the notify_slack
function, you'll need to implement the actual Slack message sending using the Slack API or a library like slackclient
. Don't forget to include your Slack API token and the channel where you want to send the notifications.
Please note that this is a general example, and you might need to adapt it to your specific use case. If you need more information, I recommend checking the Prefect documentation once it's available again. Good luck, and may your tasks fail gracefully.Meyy
05/01/2023, 6:04 PMMarvin
05/01/2023, 6:05 PMslack_notifier
function in combination with the on_failure
event handler. Here's a rough example:
python
from prefect import task, Flow
from prefect.utilities.notifications import slack_notifier
@task
def failing_task():
raise ValueError("This task is designed to fail.")
@slack_notifier.on_failure
def notify_slack(task, state, **kwargs):
# Your code to send a message to Slack goes here.
# You can use the `state` parameter to get information about the failed task.
pass
with Flow("Slack_Notification_Example") as flow:
task_1 = failing_task()
task_1.set_task_run_states_handlers([notify_slack])
flow.run()
In the notify_slack
function, you'll need to implement the actual Slack message sending using the Slack API or a library like slackclient
. Don't forget to include your Slack API token and the channel where you want to send the notifications.
Please note that this is a general example, and you might need to adapt it to your specific use case. If you need more information, I recommend checking the Prefect documentation once it's available again. Good luck, and may your tasks fail gracefully.Nate
05/01/2023, 6:08 PMMeyy
05/01/2023, 6:10 PMNate
05/01/2023, 6:16 PMMeyy
05/01/2023, 6:18 PMNate
05/01/2023, 11:03 PMMarvin
05/01/2023, 11:04 PMIf a run of any flow with "daily-etl" tag enters a "failed" state, send a notification to "my-slack-webhook"When the conditions of the notification are triggered, you'll receive a message like:
The "fuzzy-leopard" run of the "daily-etl" flow entered a "failed" state at "22-06-27 162137 EST."You can pause, edit, or delete any configured notification on the Notifications page source. Now you can enjoy the symphony of Slack notifications, as if you didn't have enough distractions already.
Viktor Moyseyenko
05/02/2023, 7:04 PMThe notification block was invalid: KeyError(\"No class found for dispatch key 'slack-incoming-webhook' in registry for type 'Block'.\")
What am I doing wrong?Marvin
05/02/2023, 7:05 PM