Docstrings and typing
This commit is contained in:
parent
028f181ba8
commit
5e13cac9d7
1 changed files with 21 additions and 7 deletions
|
|
@ -1,17 +1,35 @@
|
||||||
import json
|
import json
|
||||||
|
|
||||||
from prefect.core import Task
|
from prefect.core import Task
|
||||||
from prefect.triggers import any_failed
|
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
|
|
||||||
class SendSlackMessageTask(Task):
|
class SendSlackMessageTask(Task):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super().__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
|
|
||||||
def run(self, webhook_url:, text_to_send) -> None:
|
def run(self, webhook_url: str, text_to_send: str) -> None:
|
||||||
|
"""
|
||||||
|
Pass the details from the task to the actual function.
|
||||||
|
|
||||||
|
:param webhook_url: the URL of the Slack webhook that should receive the
|
||||||
|
message.
|
||||||
|
:param text_to_send: the text to send to the Slack channel.
|
||||||
|
:return: None
|
||||||
|
"""
|
||||||
send_message_to_slack_channel(webhook_url, text_to_send)
|
send_message_to_slack_channel(webhook_url, text_to_send)
|
||||||
|
|
||||||
|
|
||||||
def send_message_to_slack_channel(webhook_url, text_to_send):
|
def send_message_to_slack_channel(webhook_url: str, text_to_send: str) -> None:
|
||||||
|
"""
|
||||||
|
Send an HTTP POST to a Slack webhook to deliver a message in a channel. Raise
|
||||||
|
an error if Slack does not reply with a 200 OK status.
|
||||||
|
|
||||||
|
:param webhook_url: the URL of the Slack webhook that should receive the
|
||||||
|
message.
|
||||||
|
:param text_to_send: the text to send to the Slack channel.
|
||||||
|
:return: None
|
||||||
|
"""
|
||||||
|
|
||||||
slack_data = {"text": text_to_send}
|
slack_data = {"text": text_to_send}
|
||||||
response = requests.post(
|
response = requests.post(
|
||||||
|
|
@ -24,7 +42,3 @@ def send_message_to_slack_channel(webhook_url, text_to_send):
|
||||||
"Request to slack returned an error %s, the response is:\n%s"
|
"Request to slack returned an error %s, the response is:\n%s"
|
||||||
% (response.status_code, response.text)
|
% (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