@@ -261,7 +261,7 @@ func HandleGetNotifications(resp http.ResponseWriter, request *http.Request) {
261261
262262// how to make sure that the notification workflow bucket always empties itself:
263263// call sendToNotificationWorkflow with the first cached notification
264- func sendToNotificationWorkflow (ctx context.Context , notification Notification , userApikey , workflowId string , relieveNotifications bool ) error {
264+ func sendToNotificationWorkflow (ctx context.Context , notification Notification , userApikey , workflowId string , relieveNotifications bool , authOrg Org ) error {
265265 /*
266266 // FIXME: Was used for disabling it before due to possible issues with infinite loops.
267267 if project.Environment != "onprem" {
@@ -449,7 +449,7 @@ func sendToNotificationWorkflow(ctx context.Context, notification Notification,
449449 totalTimeElapsed ,
450450 bucketingMinutesInt ,
451451 )
452- _ = sendToNotificationWorkflow (ctx , notification , userApikey , workflowId , true )
452+ _ = sendToNotificationWorkflow (ctx , notification , userApikey , workflowId , true , authOrg )
453453 err = DeleteCache (ctx , cacheKey )
454454 if err != nil {
455455 log .Printf ("[ERROR] Failed deleting cached notifications %s for notification %s: %s. Assuming everything is okay and moving on" ,
@@ -497,9 +497,10 @@ func sendToNotificationWorkflow(ctx context.Context, notification Notification,
497497
498498 executionUrl := fmt .Sprintf ("%s/api/v1/workflows/%s/execute" , backendUrl , workflowId )
499499 //log.Printf("\n\n[DEBUG] Notification workflow: %s. APIKEY: %#v\n\n", executionUrl, userApikey)
500- client := & http.Client {
501- Timeout : 10 * time .Second ,
502- }
500+ client := GetExternalClient (executionUrl )
501+
502+ // Set timeout to 30 sec
503+ client .Timeout = 30 * time .Second
503504
504505 req , err := http .NewRequest (
505506 "POST" ,
@@ -508,7 +509,7 @@ func sendToNotificationWorkflow(ctx context.Context, notification Notification,
508509 )
509510
510511 req .Header .Add ("Authorization" , fmt .Sprintf (`Bearer %s` , userApikey ))
511- req .Header .Add ("Org-Id" , notification . OrgId )
512+ req .Header .Add ("Org-Id" , authOrg . Id )
512513 newresp , err := client .Do (req )
513514 if err != nil {
514515 return err
@@ -650,6 +651,8 @@ func CreateOrgNotification(ctx context.Context, title, description, referenceUrl
650651 project .Environment = "worker"
651652 }
652653
654+ log .Printf ("[DEBUG] Creating org notification! %s. Env: %s" , orgId , project .Environment )
655+
653656 // Check if the referenceUrl is already in cache or not
654657 if len (referenceUrl ) > 0 {
655658 // Have a 0-0.5 sec timeout here?
@@ -805,7 +808,7 @@ func CreateOrgNotification(ctx context.Context, title, description, referenceUrl
805808 if mainNotification .Ignored {
806809 log .Printf ("[INFO] Ignored notification %s for %s" , mainNotification .Title , mainNotification .UserId )
807810 } else {
808- err = sendToNotificationWorkflow (ctx , mainNotification , selectedApikey , org .Defaults .NotificationWorkflow , false )
811+ err = sendToNotificationWorkflow (ctx , mainNotification , selectedApikey , org .Defaults .NotificationWorkflow , false , * authOrg )
809812 if err != nil {
810813 if ! strings .Contains (err .Error (), "cache stored" ) && ! strings .Contains (err .Error (), "Same workflow" ) {
811814 log .Printf ("[ERROR] Failed sending notification to workflowId %s for reference %s (2): %s" , org .Defaults .NotificationWorkflow , mainNotification .Id , err )
@@ -907,7 +910,7 @@ func CreateOrgNotification(ctx context.Context, title, description, referenceUrl
907910 }
908911 }
909912
910- err = sendToNotificationWorkflow (ctx , mainNotification , selectedApikey , org .Defaults .NotificationWorkflow , false )
913+ err = sendToNotificationWorkflow (ctx , mainNotification , selectedApikey , org .Defaults .NotificationWorkflow , false , * authOrg )
911914 if err != nil {
912915 log .Printf ("[ERROR] Failed sending notification to workflowId %s for reference %s: %s" , org .Defaults .NotificationWorkflow , mainNotification .Id , err )
913916 }
0 commit comments