@@ -200,7 +200,6 @@ class SlackNotificationManger(NotificationManagerHelpers):
200200
201201 """Manger for slack notifications and their helpers."""
202202
203- @app .task (base = DojoAsyncTask )
204203 def send_slack_notification (
205204 self ,
206205 event : str ,
@@ -317,7 +316,6 @@ class MSTeamsNotificationManger(NotificationManagerHelpers):
317316
318317 """Manger for Microsoft Teams notifications and their helpers."""
319318
320- @app .task (base = DojoAsyncTask )
321319 def send_msteams_notification (
322320 self ,
323321 event : str ,
@@ -367,7 +365,6 @@ class EmailNotificationManger(NotificationManagerHelpers):
367365
368366 """Manger for email notifications and their helpers."""
369367
370- @app .task (base = DojoAsyncTask )
371368 def send_mail_notification (
372369 self ,
373370 event : str ,
@@ -418,7 +415,6 @@ class WebhookNotificationManger(NotificationManagerHelpers):
418415 ERROR_PERMANENT = "permanent"
419416 ERROR_TEMPORARY = "temporary"
420417
421- @app .task (base = DojoAsyncTask )
422418 def send_webhooks_notification (
423419 self ,
424420 event : str ,
@@ -477,11 +473,7 @@ def send_webhooks_notification(
477473 endpoint .first_error = now
478474 endpoint .status = Notification_Webhooks .Status .STATUS_INACTIVE_TMP
479475 # In case of failure within one day, endpoint can be deactivated temporally only for one minute
480- self ._webhook_reactivation .apply_async (
481- args = [self ],
482- kwargs = {"endpoint_id" : endpoint .pk },
483- countdown = 60 ,
484- )
476+ webhook_reactivation .apply_async (kwargs = {"endpoint_id" : endpoint .pk }, countdown = 60 )
485477 # There is no reason to keep endpoint active if it is returning 4xx errors
486478 else :
487479 endpoint .status = Notification_Webhooks .Status .STATUS_INACTIVE_PERMANENT
@@ -556,7 +548,6 @@ def _test_webhooks_notification(self, endpoint: Notification_Webhooks) -> None:
556548 # in "send_webhooks_notification", we are doing deeper analysis, why it failed
557549 # for now, "raise_for_status" should be enough
558550
559- @app .task (ignore_result = True )
560551 def _webhook_reactivation (self , endpoint_id : int , ** _kwargs : dict ):
561552 endpoint = Notification_Webhooks .objects .get (pk = endpoint_id )
562553 # User already changed status of endpoint
@@ -830,9 +821,9 @@ def _process_notifications(
830821 ):
831822 logger .debug ("Sending Slack Notification" )
832823 dojo_dispatch_task (
833- self . _get_manager_instance ( "slack" ). send_slack_notification ,
824+ send_slack_notification ,
834825 event ,
835- user = notifications .user ,
826+ user_id = getattr ( notifications .user , "id" , None ) ,
836827 ** kwargs ,
837828 )
838829
@@ -843,9 +834,9 @@ def _process_notifications(
843834 ):
844835 logger .debug ("Sending MSTeams Notification" )
845836 dojo_dispatch_task (
846- self . _get_manager_instance ( "msteams" ). send_msteams_notification ,
837+ send_msteams_notification ,
847838 event ,
848- user = notifications .user ,
839+ user_id = getattr ( notifications .user , "id" , None ) ,
849840 ** kwargs ,
850841 )
851842
@@ -856,9 +847,9 @@ def _process_notifications(
856847 ):
857848 logger .debug ("Sending Mail Notification" )
858849 dojo_dispatch_task (
859- self . _get_manager_instance ( "mail" ). send_mail_notification ,
850+ send_mail_notification ,
860851 event ,
861- user = notifications .user ,
852+ user_id = getattr ( notifications .user , "id" , None ) ,
862853 ** kwargs ,
863854 )
864855
@@ -869,13 +860,42 @@ def _process_notifications(
869860 ):
870861 logger .debug ("Sending Webhooks Notification" )
871862 dojo_dispatch_task (
872- self . _get_manager_instance ( "webhooks" ). send_webhooks_notification ,
863+ send_webhooks_notification ,
873864 event ,
874- user = notifications .user ,
865+ user_id = getattr ( notifications .user , "id" , None ) ,
875866 ** kwargs ,
876867 )
877868
878869
870+ @app .task (base = DojoAsyncTask )
871+ def send_slack_notification (event : str , user_id : int | None = None , ** kwargs : dict ) -> None :
872+ user = Dojo_User .objects .get (pk = user_id ) if user_id else None
873+ SlackNotificationManger ().send_slack_notification (event , user = user , ** kwargs )
874+
875+
876+ @app .task (base = DojoAsyncTask )
877+ def send_msteams_notification (event : str , user_id : int | None = None , ** kwargs : dict ) -> None :
878+ user = Dojo_User .objects .get (pk = user_id ) if user_id else None
879+ MSTeamsNotificationManger ().send_msteams_notification (event , user = user , ** kwargs )
880+
881+
882+ @app .task (base = DojoAsyncTask )
883+ def send_mail_notification (event : str , user_id : int | None = None , ** kwargs : dict ) -> None :
884+ user = Dojo_User .objects .get (pk = user_id ) if user_id else None
885+ EmailNotificationManger ().send_mail_notification (event , user = user , ** kwargs )
886+
887+
888+ @app .task (base = DojoAsyncTask )
889+ def send_webhooks_notification (event : str , user_id : int | None = None , ** kwargs : dict ) -> None :
890+ user = Dojo_User .objects .get (pk = user_id ) if user_id else None
891+ WebhookNotificationManger ().send_webhooks_notification (event , user = user , ** kwargs )
892+
893+
894+ @app .task (ignore_result = True )
895+ def webhook_reactivation (endpoint_id : int , ** _kwargs : dict ) -> None :
896+ WebhookNotificationManger ()._webhook_reactivation (endpoint_id = endpoint_id )
897+
898+
879899@app .task (ignore_result = True )
880900def webhook_status_cleanup (* _args : list , ** _kwargs : dict ):
881901 # If some endpoint was affected by some outage (5xx, 429, Timeout) but it was clean during last 24 hours,
@@ -903,4 +923,4 @@ def webhook_status_cleanup(*_args: list, **_kwargs: dict):
903923 )
904924 for endpoint in broken_endpoints :
905925 manager = WebhookNotificationManger ()
906- manager ._webhook_reactivation (manager , endpoint_id = endpoint .pk )
926+ manager ._webhook_reactivation (endpoint_id = endpoint .pk )
0 commit comments