Skip to content

Commit 009f328

Browse files
committed
Fixed issues with notification workflow forwarding from child to parents
1 parent ea39723 commit 009f328

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

health.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2026,6 +2026,7 @@ func GetStaticWorkflowHealth(ctx context.Context, workflow Workflow) (Workflow,
20262026

20272027
if len(triggerType) == 0 {
20282028
log.Printf("[WARNING] No TriggerType specified for User Input node %s in %s (%s)", trigger.Label, workflow.Name, workflow.ID)
2029+
workflow.Errors = append(workflow.Errors, fmt.Sprintf("No TriggerType specified for User Input node '%s'", trigger.Label))
20292030
if workflow.PreviouslySaved {
20302031
//resp.WriteHeader(401)
20312032
//resp.Write([]byte(fmt.Sprintf(`{"success": false, "reason": "No contact option specified in user input"}`)))

notifications.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

shared.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7383,7 +7383,7 @@ func diffWorkflows(oldWorkflow Workflow, parentWorkflow Workflow, update bool) {
73837383
newChildTriggers = append(newChildTriggers, trigger)
73847384
}
73857385

7386-
log.Printf("New triggers: %#v", newChildTriggers)
7386+
//log.Printf("New triggers: %#v", len(newChildTriggers))
73877387

73887388
childWorkflow.Triggers = newChildTriggers
73897389
childTriggers = childWorkflow.Triggers
@@ -8502,7 +8502,9 @@ func SaveWorkflow(resp http.ResponseWriter, request *http.Request) {
85028502
// contains reference objects in the workflow that causes
85038503
// e.g. authenticationIds to be reset.
85048504
// This is a temporary fix to avoid it.
8505-
go diffWorkflowWrapper(newWorkflow)
8505+
// FIXME: Removed goroutine. Does it matter?
8506+
// Makes the timing problem go away.
8507+
diffWorkflowWrapper(newWorkflow)
85068508
}
85078509

85088510
workflow.UpdatedBy = user.Username

0 commit comments

Comments
 (0)