Skip to content

Commit

Permalink
Swallow send exceptions (#4034)
Browse files Browse the repository at this point in the history
  • Loading branch information
whitdog47 authored Nov 27, 2023
1 parent f5b49ca commit 1a99d5d
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 19 deletions.
6 changes: 6 additions & 0 deletions src/dispatch/evergreen/scheduled.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ def create_evergreen_reminder(
db_session: SessionLocal, project: Project, owner_email: str, resource_groups: Any
):
"""Contains the logic for evergreen reminders."""
if not owner_email:
log.warning(
"Evergreen reminder not sent. No owner email. Project: {project.name}. Organization: {project.organization.name}"
)
return

plugin = plugin_service.get_active_instance(
db_session=db_session, plugin_type="email", project_id=project.id
)
Expand Down
1 change: 1 addition & 0 deletions src/dispatch/plugins/dispatch_slack/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ class SlackAPIErrorCode(DispatchEnum):
USERS_NOT_FOUND = "users_not_found"
VIEW_NOT_FOUND = "not_found" # Could not find corresponding view for the provided view_id
VIEW_EXPIRED = "expired_trigger_id" # The provided trigger_id is no longer valid
IS_ARCHIVED = "is_archived" # Channel is archived
49 changes: 30 additions & 19 deletions src/dispatch/plugins/dispatch_slack/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
unarchive_conversation,
update_message,
)
from slack_sdk.errors import SlackApiError
from .enums import SlackAPIErrorCode

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -162,26 +164,35 @@ def send(
**kwargs,
):
"""Sends a new message based on data and type."""
client = create_slack_client(self.configuration)
messages = []
if not blocks:
blocks = create_message_blocks(message_template, notification_type, items, **kwargs)

for c in chunks(blocks, 50):
messages.append(
send_message(
client,
conversation_id,
text,
ts,
Message(blocks=c).build()["blocks"],
persist,
try:
client = create_slack_client(self.configuration)
messages = []
if not blocks:
blocks = create_message_blocks(message_template, notification_type, items, **kwargs)

for c in chunks(blocks, 50):
messages.append(
send_message(
client,
conversation_id,
text,
ts,
Message(blocks=c).build()["blocks"],
persist,
)
)
)
else:
for c in chunks(blocks, 50):
messages.append(send_message(client, conversation_id, text, ts, c, persist))
return messages
else:
for c in chunks(blocks, 50):
messages.append(send_message(client, conversation_id, text, ts, c, persist))
return messages
except SlackApiError as exception:
error = exception.response["error"]
if error == SlackAPIErrorCode.IS_ARCHIVED:
# swallow send errors if the channel is archived
message = f"SlackAPIError trying to send: {exception.response}. Message: {text}. Type: {notification_type}"
logger.error(message)
else:
raise exception

def send_direct(
self,
Expand Down

0 comments on commit 1a99d5d

Please sign in to comment.