Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Swallow send exceptions #4034

Merged
merged 4 commits into from
Nov 27, 2023
Merged
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
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
Loading