Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions gitops_server/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@
# The slack channel ID starts with C
SLACK_CHANNEL_ID = os.environ.get("SLACK_CHANNEL_ID", "")

SLACK_ALERT_CHANNEL_ID = os.environ.get("SLACK_ALERT_CHANNEL_ID", "")

# How many parallel deploys can be done at once
GITOPS_MAX_PARALLEL_DEPLOYS = os.environ.get("GITOPS_MAX_PARALLEL_DEPLOYS", "5")
15 changes: 13 additions & 2 deletions gitops_server/utils/slack.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,22 @@ def __str__(self) -> str:
return f"<!subteam^{self.id}|{self.name}>"


async def post_alert(message: str) -> str | None:
"""
Post a message to a slack alert channel (if it's configured) or the default slack channel
"""
return await post_to_channel(message, channel_id=settings.SLACK_ALERT_CHANNEL_ID or settings.SLACK_CHANNEL_ID)


async def post(message: str) -> str | None:
"""Post a message to a slack channel"""
return await post_to_channel(message, channel_id=settings.SLACK_CHANNEL_ID)


async def post_to_channel(message: str, channel_id: str | None) -> str | None:
logger.info("POSTING TO SLACK")
if settings.SLACK_TOKEN and settings.SLACK_CHANNEL_ID:
response = client.chat_postMessage(channel=settings.SLACK_CHANNEL_ID, text=message)
if settings.SLACK_TOKEN and channel_id:
response = client.chat_postMessage(channel=channel_id, text=message)
if response.status_code >= 300:
logger.warning("Failed to post a message to slack (see below):")
logger.error(f"{message}", exc_info=True)
Expand Down
2 changes: 1 addition & 1 deletion gitops_server/workers/deployer/deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ async def post_result(self, app: App, result: UpdateAppResult, deployer: "Deploy
deploy_result["slack_message"]
or f"Failed to deploy app `{result['app_name']}` for cluster `{settings.CLUSTER_NAME}`:\n>>>{result['output']}"
)
await slack.post(message)
await slack.post_alert(message)
else:
self.successful_apps.add(app.name)
await handle_successful_deploy(app, result, deployer)
Expand Down
Loading