You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2020/06/03 02:36:53 UTC

[GitHub] [incubator-superset] bkyryliuk commented on a change in pull request #9810: feat: superset report slack integration

bkyryliuk commented on a change in pull request #9810:
URL: https://github.com/apache/incubator-superset/pull/9810#discussion_r434275783



##########
File path: superset/tasks/schedules.py
##########
@@ -62,55 +63,94 @@
 WEBDRIVER_BASEURL = config["WEBDRIVER_BASEURL"]
 WEBDRIVER_BASEURL_USER_FRIENDLY = config["WEBDRIVER_BASEURL_USER_FRIENDLY"]
 
-EmailContent = namedtuple("EmailContent", ["body", "data", "images"])
+ReportContent = namedtuple(
+    "EmailContent",
+    [
+        "body",  # email body
+        "data",  # attachments
+        "images",  # embedded images for the email
+        "slack_message",  # html not supported, only markdown
+        # attachments for the slack message, embedding not supported
+        "slack_attachment",
+    ],
+)
 
 
-def _get_recipients(
-    schedule: Union[DashboardEmailSchedule, SliceEmailSchedule]
+def _get_email_to_and_bcc(
+    recipients: str, deliver_as_group: bool
 ) -> Iterator[Tuple[str, str]]:
     bcc = config["EMAIL_REPORT_BCC_ADDRESS"]
 
-    if schedule.deliver_as_group:
-        to = schedule.recipients
+    if deliver_as_group:
+        to = recipients
         yield (to, bcc)
     else:
-        for to in get_email_address_list(schedule.recipients):
+        for to in get_email_address_list(recipients):
             yield (to, bcc)
 
 
-def _deliver_email(
-    schedule: Union[DashboardEmailSchedule, SliceEmailSchedule],
+def _deliver_slack(slack_channel: str, subject: str, body: str, file: bytes,) -> None:
+    try:
+        client = WebClient(token=config["SLACK_API_TOKEN"], proxy=config["SLACK_PROXY"])
+        response = client.files_upload(
+            channels=slack_channel, file=file, initial_comment=body, title=subject
+        )
+        logger.info(f"Sent the report to the slack {slack_channel}")
+        assert response["file"], str(response)  # the uploaded file
+    except SlackApiError as ex:
+        if ex.response["error"] == "ratelimited":
+            delay = int(ex.response.headers["Retry-After"])
+            logger.info(f"Rate limited. Retrying in {delay} seconds")
+            time.sleep(delay)
+            client.files_upload(

Review comment:
       sounds good, will keep it simple




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org