From 5e13cac9d726cee7f983ff782ce80a01b29e15c6 Mon Sep 17 00:00:00 2001 From: Pablo Martin Date: Fri, 30 Dec 2022 11:35:31 +0100 Subject: [PATCH] Docstrings and typing --- lolafect/slack.py | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/lolafect/slack.py b/lolafect/slack.py index edf1dcc..71141f9 100644 --- a/lolafect/slack.py +++ b/lolafect/slack.py @@ -1,17 +1,35 @@ 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: + 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) -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} 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" % (response.status_code, response.text) ) - - -send_message_to_slack_channel_on_upstream_all_successful = SendSlackMessageTask() -send_error_warning_to_slack = SendSlackMessageTask(trigger=any_failed)