@@ -559,15 +559,6 @@ func WatchdogNotificationJob(ctx context.Context, notificationID string, interva
559559// SendWatchdogNotification sends a watchdog notification containing statistics
560560// for the specified notification
561561func SendWatchdogNotification (ctx context.Context , notificationID string ) error {
562- stats , err := query .GetNotificationStats (ctx , notificationID )
563- if err != nil {
564- return fmt .Errorf ("failed to get notification statistics: %w" , err )
565- }
566-
567- if len (stats ) == 0 {
568- return nil
569- }
570-
571562 notificationUUID , err := uuid .Parse (notificationID )
572563 if err != nil {
573564 return fmt .Errorf ("failed to parse notification ID: %w" , err )
@@ -578,26 +569,46 @@ func SendWatchdogNotification(ctx context.Context, notificationID string) error
578569 return fmt .Errorf ("failed to get notification: %w" , err )
579570 }
580571
581- celEnv := & celVariables {
582- Summary : stats [0 ],
583- }
572+ if notification .PlaybookID == nil {
573+ // NOTE: Watchdog notifications aren't sent to playbook recievers.
584574
585- payload := NotificationEventPayload {
586- EventName : "notification.watchdog" ,
587- EventCreatedAt : time .Now (),
588- PersonID : notification .PersonID ,
589- TeamID : notification .TeamID ,
590- }
575+ // Manually craft a payload (unlike other payloads that are generated from events)
576+ // This allows us to bypass the event queue and process synchronously
577+ payload := NotificationEventPayload {
578+ EventName : api .EventWatchdog ,
579+ EventCreatedAt : time .Now (),
580+ ID : notificationUUID ,
581+ PersonID : notification .PersonID ,
582+ NotificationID : notificationUUID ,
583+ TeamID : notification .TeamID ,
584+ Properties : fmt .Appendf (nil , `{"id": "%s"}` , notificationUUID .String ()),
585+ }
586+ if len (notification .CustomNotifications ) > 0 {
587+ payload .CustomService = & notification .CustomNotifications [0 ]
588+ }
591589
592- if len (notification .CustomNotifications ) > 0 {
593- payload .CustomService = & notification .CustomNotifications [0 ]
590+ if err := sendNotification (ctx , payload ); err != nil {
591+ return fmt .Errorf ("failed to send watchdog notification to primary recipient: %w" , err )
592+ }
594593 }
595594
596- nCtx := NewContext (ctx , notificationUUID )
597- nCtx .WithSource (payload .EventName , payload .ID )
598- if err := PrepareAndSendEventNotification (nCtx , payload , celEnv ); err != nil {
599- return fmt .Errorf ("failed to send watchdog notification: %w" , err )
595+ if notification .FallbackPlaybookID == nil {
596+ // Also, send to fallback recipient
597+ payload := NotificationEventPayload {
598+ EventName : api .EventWatchdog ,
599+ EventCreatedAt : time .Now (),
600+ ID : notificationUUID ,
601+ NotificationID : notificationUUID ,
602+ PersonID : notification .FallbackPersonID ,
603+ TeamID : notification .FallbackTeamID ,
604+ CustomService : notification .FallbackCustomNotification ,
605+ Properties : fmt .Appendf (nil , `{"id": "%s"}` , notificationUUID .String ()),
606+ }
607+
608+ if err := sendNotification (ctx , payload ); err != nil {
609+ return fmt .Errorf ("failed to send watchdog notification to fallback recipient: %w" , err )
610+ }
600611 }
601612
602- return nCtx . EndLog ()
613+ return nil
603614}
0 commit comments