Skip to content
This repository was archived by the owner on May 5, 2025. It is now read-only.
Draft
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
13 changes: 3 additions & 10 deletions services/notification/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@
from services.comparison import ComparisonProxy
from services.decoration import Decoration
from services.license import is_properly_licensed
from services.notification.commit_notifications import (
create_or_update_commit_notification_from_notification_result,
)
from services.notification.commit_notifications import store_notification_results
from services.notification.notifiers import (
StatusType,
get_all_notifier_classes_mapping,
Expand Down Expand Up @@ -307,6 +305,8 @@ def notify(self, comparison: ComparisonProxy) -> list[IndividualResult]:
for notifier in all_other_notifiers
)

store_notification_results(comparison, results)

return [
IndividualResult(
notifier=notifier.name, title=notifier.title, result=result
Expand Down Expand Up @@ -351,13 +351,6 @@ def notify_individual_notifier(
except Exception:
log.exception("Individual notifier failed", extra=log_extra)
return notifier, res
finally:
if res is None or res.notification_attempted:
# only running if there is no result (indicating some exception)
# or there was an actual attempt
create_or_update_commit_notification_from_notification_result(
comparison, notifier, res
)


def split_notifiers(
Expand Down
17 changes: 17 additions & 0 deletions services/notification/commit_notifications.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging

import sentry_sdk
from sqlalchemy.orm.session import Session

from database.enums import NotificationState
Expand All @@ -13,6 +14,22 @@
log = logging.getLogger(__name__)


@sentry_sdk.trace
def store_notification_results(
comparison: ComparisonProxy,
results: list[tuple[AbstractBaseNotifier, NotificationResult | None]],
):
# TODO: we should change this to a batch "INSERT ON CONFLICT UPDATE" eventually,
# as this currently results in quite some inefficient query patterns.
for notifier, result in results:
if result is None or result.notification_attempted:
# only running if there is no result (indicating some exception)
# or there was an actual attempt
create_or_update_commit_notification_from_notification_result(
comparison, notifier, result
)


def create_or_update_commit_notification_from_notification_result(
comparison: ComparisonProxy,
notifier: AbstractBaseNotifier,
Expand Down
Loading