Copied over code from flow
This commit is contained in:
parent
630701e0da
commit
028f181ba8
1 changed files with 30 additions and 2 deletions
|
|
@ -1,2 +1,30 @@
|
|||
def say_hi():
|
||||
return "Slack says hi"
|
||||
import json
|
||||
|
||||
from prefect.core import Task
|
||||
from prefect.triggers import any_failed
|
||||
import requests
|
||||
class SendSlackMessageTask(Task):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
def run(self, webhook_url:, text_to_send) -> None:
|
||||
send_message_to_slack_channel(webhook_url, text_to_send)
|
||||
|
||||
|
||||
def send_message_to_slack_channel(webhook_url, text_to_send):
|
||||
|
||||
slack_data = {"text": text_to_send}
|
||||
response = requests.post(
|
||||
webhook_url,
|
||||
data=json.dumps(slack_data),
|
||||
headers={"Content-Type": "application/json"},
|
||||
)
|
||||
if response.status_code != 200:
|
||||
raise ValueError(
|
||||
"Request to slack returned an error %s, the response is:\n%s"
|
||||
% (response.status_code, response.text)
|
||||
)
|
||||
|
||||
|
||||
send_message_to_slack_channel_on_upstream_all_successful = SendSlackMessageTask()
|
||||
send_error_warning_to_slack = SendSlackMessageTask(trigger=any_failed)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue