|
18 | 18 |
|
19 | 19 | from dojo import __version__ as dd_version |
20 | 20 | from dojo.authorization.roles_permissions import Permissions |
21 | | -from dojo.celery_dispatch import dojo_dispatch_task |
22 | 21 | from dojo.decorators import we_want_async |
23 | 22 | from dojo.labels import get_labels |
24 | 23 | from dojo.models import ( |
@@ -834,58 +833,55 @@ def _process_notifications( |
834 | 833 |
|
835 | 834 | # Some errors should not be pushed to all channels, only to alerts. |
836 | 835 | # For example reasons why JIRA Issues: https://github.com/DefectDojo/django-DefectDojo/issues/11575 |
| 836 | + # Per-channel sends run synchronously inside the surrounding async_create_notification |
| 837 | + # task body. Dispatching inner Celery tasks would require JSON-serializable kwargs, but |
| 838 | + # callers pass model instances (finding/test/engagement/product/...) and refetching every |
| 839 | + # one of them per channel would multiply DB queries; running synchronously avoids both. |
837 | 840 | if not alert_only: |
| 841 | + user_id = getattr(notifications.user, "id", None) |
838 | 842 | if self.system_settings.enable_slack_notifications and "slack" in getattr( |
839 | 843 | notifications, |
840 | 844 | event, |
841 | 845 | notifications.other, |
842 | 846 | ): |
843 | 847 | logger.debug("Sending Slack Notification") |
844 | | - dojo_dispatch_task( |
845 | | - send_slack_notification, |
846 | | - event, |
847 | | - user_id=getattr(notifications.user, "id", None), |
848 | | - **kwargs, |
849 | | - ) |
| 848 | + try: |
| 849 | + send_slack_notification.run(event, user_id=user_id, **kwargs) |
| 850 | + except Exception: |
| 851 | + logger.exception("Failed to send Slack notification for event %s", event) |
850 | 852 |
|
851 | 853 | if self.system_settings.enable_msteams_notifications and "msteams" in getattr( |
852 | 854 | notifications, |
853 | 855 | event, |
854 | 856 | notifications.other, |
855 | 857 | ): |
856 | 858 | logger.debug("Sending MSTeams Notification") |
857 | | - dojo_dispatch_task( |
858 | | - send_msteams_notification, |
859 | | - event, |
860 | | - user_id=getattr(notifications.user, "id", None), |
861 | | - **kwargs, |
862 | | - ) |
| 859 | + try: |
| 860 | + send_msteams_notification.run(event, user_id=user_id, **kwargs) |
| 861 | + except Exception: |
| 862 | + logger.exception("Failed to send MSTeams notification for event %s", event) |
863 | 863 |
|
864 | 864 | if self.system_settings.enable_mail_notifications and "mail" in getattr( |
865 | 865 | notifications, |
866 | 866 | event, |
867 | 867 | notifications.other, |
868 | 868 | ): |
869 | 869 | logger.debug("Sending Mail Notification") |
870 | | - dojo_dispatch_task( |
871 | | - send_mail_notification, |
872 | | - event, |
873 | | - user_id=getattr(notifications.user, "id", None), |
874 | | - **kwargs, |
875 | | - ) |
| 870 | + try: |
| 871 | + send_mail_notification.run(event, user_id=user_id, **kwargs) |
| 872 | + except Exception: |
| 873 | + logger.exception("Failed to send Mail notification for event %s", event) |
876 | 874 |
|
877 | 875 | if self.system_settings.enable_webhooks_notifications and "webhooks" in getattr( |
878 | 876 | notifications, |
879 | 877 | event, |
880 | 878 | notifications.other, |
881 | 879 | ): |
882 | 880 | logger.debug("Sending Webhooks Notification") |
883 | | - dojo_dispatch_task( |
884 | | - send_webhooks_notification, |
885 | | - event, |
886 | | - user_id=getattr(notifications.user, "id", None), |
887 | | - **kwargs, |
888 | | - ) |
| 881 | + try: |
| 882 | + send_webhooks_notification.run(event, user_id=user_id, **kwargs) |
| 883 | + except Exception: |
| 884 | + logger.exception("Failed to send Webhooks notification for event %s", event) |
889 | 885 |
|
890 | 886 |
|
891 | 887 | def process_tag_notifications(request, note, parent_url, parent_title): |
|
0 commit comments