Skip to content

Commit

Permalink
Differentiate between slack channels (#359)
Browse files Browse the repository at this point in the history
  • Loading branch information
AetherUnbound committed Feb 15, 2022
1 parent 6dd5cb3 commit 9555374
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
7 changes: 5 additions & 2 deletions env.template
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,12 @@ AIRFLOW_CONN_AWS_DEFAULT=aws://test_key:test_secret@?region_name=us-east-1&host=
# Change the following line in prod to use the appropriate DB
AIRFLOW_CONN_POSTGRES_OPENLEDGER_UPSTREAM=postgres://deploy:deploy@postgres:5432/openledger
AIRFLOW_CONN_POSTGRES_OPENLEDGER_TESTING=postgres://deploy:deploy@postgres:5432/openledger
# Slack notification webhook connection info (this must be URL encoded, with a
# Slack webhook connection info (this must be URL encoded, with a
# pre-pended https://, e.g. "https://https%3A%2F%2Fhooks.slack.com%2Fservices%2everythingelse")
AIRFLOW_CONN_SLACK=https://slack
# A distinction is made here between "notifications" and "alerts", the former being
# useful updates and the latter being alarms or actionable errors.
AIRFLOW_CONN_SLACK_NOTIFICATIONS=https://slack
AIRFLOW_CONN_SLACK_ALERTS=https://slack

OPENLEDGER_CONN_ID=postgres_openledger_upstream
TEST_CONN_ID=postgres_openledger_testing
Expand Down
9 changes: 5 additions & 4 deletions openverse_catalog/dags/common/slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@
from requests import Response


SLACK_CONN_ID = "slack"
SLACK_NOTIFICATIONS_CONN_ID = "slack_notifications"
SLACK_ALERTS_CONN_ID = "slack_alerts"
JsonDict = dict[str, Any]
log = logging.getLogger(__name__)

Expand All @@ -66,7 +67,7 @@ def __init__(
icon_emoji: str = ":airflow:",
unfurl_links: bool = True,
unfurl_media: bool = True,
http_conn_id: str = SLACK_CONN_ID,
http_conn_id: str = SLACK_NOTIFICATIONS_CONN_ID,
):

self.http = HttpHook(method="POST", http_conn_id=http_conn_id)
Expand Down Expand Up @@ -211,7 +212,7 @@ def send_message(
username: str = "Airflow",
icon_emoji: str = ":airflow:",
markdown: bool = True,
http_conn_id: str = SLACK_CONN_ID,
http_conn_id: str = SLACK_NOTIFICATIONS_CONN_ID,
) -> None:
"""Send a simple slack message, convenience message for short/simple messages."""
s = SlackMessage(username, icon_emoji, http_conn_id=http_conn_id)
Expand All @@ -225,7 +226,7 @@ def on_failure_callback(context: dict) -> None:
Errors are only sent out in production and if a Slack connection is defined.
"""
# Exit early if no slack connection exists
hook = HttpHook(http_conn_id=SLACK_CONN_ID)
hook = HttpHook(http_conn_id=SLACK_ALERTS_CONN_ID)
try:
hook.get_conn()
except AirflowNotFoundException:
Expand Down

0 comments on commit 9555374

Please sign in to comment.