From 72f465c6805e2d19fd48478910381c05f817d8e0 Mon Sep 17 00:00:00 2001 From: Frikky Date: Tue, 3 Sep 2024 20:56:00 +0200 Subject: [PATCH] Fixed workflow execution validation system + UI --- shared.go | 166 ++++++++++++++++++++--------------------------------- structs.go | 1 + 2 files changed, 62 insertions(+), 105 deletions(-) diff --git a/shared.go b/shared.go index 265683f..4b7230b 100755 --- a/shared.go +++ b/shared.go @@ -28304,7 +28304,7 @@ func checkExecutionStatus(ctx context.Context, exec *WorkflowExecution) *Workflo ActionId: foundAction.ID, AppId: foundAction.AppID, AppName: foundAction.AppName, - Error: "Action failed: " + unmarshalledHttp.Reason, + Error: fmt.Sprintf("Action '%s' failed: '%s'", strings.ReplaceAll(foundAction.Label, "_", " "), unmarshalledHttp.Reason), Type: "configuration", } @@ -28402,11 +28402,13 @@ func checkExecutionStatus(ctx context.Context, exec *WorkflowExecution) *Workflo } // Replace with the apps of the subflow? - log.Printf("\n\n\nSUBFLOW: %#v\n\n\n", trigger.ID) + //log.Printf("\n\n\nSUBFLOW: %#v\n\n\n", trigger.ID) foundWorkflow := "" startNode := "" + _ = startNode waitForResults := false + _ = waitForResults for _, param := range trigger.Parameters { if param.Name == "workflow" { foundWorkflow = param.Value @@ -28421,145 +28423,97 @@ func checkExecutionStatus(ctx context.Context, exec *WorkflowExecution) *Workflo } } + if foundWorkflow == "" { continue } // Doing explicit execution IF it exists - // FIXME: Handle loops as well - if waitForResults == true { - foundExecutionIds := []string{} - - for _, res := range exec.Results { - if res.Action.ID != trigger.ID { - continue - } + foundExecutionIds := []string{} + for _, res := range exec.Results { + if res.Action.ID != trigger.ID { + continue + } + marshalledListData := []SubflowData{} + err := json.Unmarshal([]byte(res.Result), &marshalledListData) + if err != nil { + log.Printf("[ERROR] Failed unmarshalling subflow data for %s: %s", res.Action.Label, err) marshalledData := SubflowData{} err := json.Unmarshal([]byte(res.Result), &marshalledData) if err != nil { log.Printf("[ERROR] Failed unmarshalling subflow data for %s: %s", res.Action.Label, err) - continue + //continue + } else { + marshalledListData = append(marshalledListData, marshalledData) } + } + for _, marshalledData := range marshalledListData { if marshalledData.Success == false { - log.Printf("[DEBUG] Subflow %s failed to start", marshalledData.ExecutionId) + //log.Printf("[DEBUG] Subflow %s failed to start", marshalledData.ExecutionId) continue } foundExecutionIds = append(foundExecutionIds, marshalledData.ExecutionId) - break - } - - log.Printf("[DEBUG] Waiting for results. Execution IDs: %#v", foundExecutionIds) - appendedActionIds := []string{} - for _, execId := range foundExecutionIds { - subExec, err := GetWorkflowExecution(ctx, execId) - if err != nil { - log.Printf("[ERROR] Failed getting subflow execution %s for workflow %s: %s", execId, workflow.ID, err) - continue - } - - if subExec.Status == "EXECUTING" { - // FIXME: Check based on the workflow itself instead - log.Printf("[DEBUG] Subflow %s is still executing. Validation: %s", execId, subExec.Workflow.Validation.Valid) - } else { - // Check validations - log.Printf("[DEBUG] Subflow %s is finished. Validation: %#v. Validation Problems: %d", execId, subExec.Workflow.Validation.Valid, len(subExec.Workflow.Validation.Problems)) - if subExec.Workflow.Validation.Valid { - continue - } - - for _, subProblem := range subExec.Workflow.Validation.Problems { - // We keep appending for each level - if ArrayContains(appendedActionIds, subProblem.ActionId) { - continue - } - - appendedActionIds = append(appendedActionIds, subProblem.ActionId) - authenticationProblems = append(authenticationProblems, subProblem) - - } - } } + break + } - } else if !waitForResults { - log.Printf("[DEBUG] Getting workflow %s for subflow check", foundWorkflow) - subflow, err := GetWorkflow(ctx, foundWorkflow) + //log.Printf("\n\n[DEBUG] Waiting for results. Execution IDs: %#v\n\n", foundExecutionIds) + appendedActionIds := []string{} + for _, execId := range foundExecutionIds { + subExec, err := GetWorkflowExecution(ctx, execId) if err != nil { - log.Printf("[ERROR] Failed getting subflow %s for workflow %s: %s", foundWorkflow, workflow.ID, err) + log.Printf("[ERROR] Failed getting subflow execution %s for workflow %s: %s", execId, workflow.ID, err) continue } - if startNode == "" { - startNode = workflow.Start - } - - // FIXME: Look for subvalues of this one again in this ones' subflow + if subExec.Status == "EXECUTING" { + // FIXME: Check based on the workflow itself instead + //log.Printf("[DEBUG] Subflow %s is still executing. Validation: %s", execId, subExec.Workflow.Validation.Valid) - // Check for actions in the subflow - subChildNodes := FindChildNodes(*subflow, startNode, []string{}, []string{}) - log.Printf("[DEBUG] Found %d child nodes for subflow %s", len(subChildNodes), subflow.ID) - - // FIXME: May be a problem here with sub-sub workflows etc. - // Something about always being one workflow behind - if len(subflow.Validation.SubflowApps) > 0 { - for _, subProblem := range subflow.Validation.SubflowApps { - // We keep appending for each level - // This is a shitty solution, but is parsable :)) - if strings.HasSuffix(subProblem.Type, "subflow_app") { - subProblem.Type = fmt.Sprintf("subflow_%s", subProblem.Type) - } - - subProblem.Order = strings.Count(subProblem.Type, "subflow_") - subProblem.WorkflowId = subflow.ID // Override due to frontend utilization - workflow.Validation.SubflowApps = append(workflow.Validation.SubflowApps, subProblem) + // Loading the Workflows own validation in this case + oldWf, err := GetWorkflow(ctx, subExec.Workflow.ID) + if err != nil { + log.Printf("[ERROR] Failed getting subflow %s for workflow %s: %s", subExec.Workflow.ID, workflow.ID, err) + } else { + subExec.Workflow = *oldWf } + } + + // Check validations + //log.Printf("[DEBUG] Subflow %s is finished. Validation: %#v. Validation Problems: %d", execId, subExec.Workflow.Validation.Valid, len(subExec.Workflow.Validation.Problems)) + if subExec.Workflow.Validation.Valid { + continue } - for _, subAction := range subflow.Actions { - found := false - for _, childNode := range subChildNodes { - if childNode == subAction.ID { - found = true - break - } + for _, subProblem := range subExec.Workflow.Validation.Problems { + // We keep appending for each level + if ArrayContains(appendedActionIds, subProblem.ActionId) { + continue } - if subAction.ID == startNode { - found = true - } + appendedActionIds = append(appendedActionIds, subProblem.ActionId) - if !found { - continue - } + subProblem.Error = fmt.Sprintf("[SUBFLOW] %s", subProblem.Error) + subProblem.Type = "subflow_app" - if subAction.AppName == "Shuffle Workflow" || subAction.AppName == "Shuffle Tools" || strings.ToLower(subAction.AppName) == "http" { - continue - } + workflow.Validation.SubflowApps = append(workflow.Validation.SubflowApps, subProblem) + } - // FIXME: Use generic icon here? - if subAction.AppName == "Integration Framework" { - for _, param := range subAction.Parameters { - if param.Name == "app_name" { - subAction.AppName = param.Value - break - } + if len(subExec.Workflow.Validation.SubflowApps) > 0 { + for _, subProblem := range subExec.Workflow.Validation.SubflowApps { + // We keep appending for each level + if ArrayContains(appendedActionIds, subProblem.ActionId) { + continue } - } - validationProblem := ValidationProblem{ - ActionId: subAction.ID, - AppId: subAction.AppID, - AppName: subAction.AppName, - Error: trigger.ID, - Type: "subflow_app", + appendedActionIds = append(appendedActionIds, subProblem.ActionId) - WorkflowId: subflow.ID, - Waiting: waitForResults, + subProblem.Type = fmt.Sprintf("sub_%s", subProblem.Type) + workflow.Validation.SubflowApps = append(workflow.Validation.SubflowApps, subProblem) } - - workflow.Validation.SubflowApps = append(workflow.Validation.SubflowApps, validationProblem) } } } @@ -28598,6 +28552,8 @@ func checkExecutionStatus(ctx context.Context, exec *WorkflowExecution) *Workflo workflow.Validation.ExecutionId = exec.ExecutionId } + workflow.Validation.TotalProblems = len(workflow.Validation.Problems) + len(workflow.Validation.SubflowApps) + // Updating the workflow to show the right status every time for now workflowChanged = true workflow.Validation.ExecutionId = exec.ExecutionId diff --git a/structs.go b/structs.go index 9938429..cae95b0 100755 --- a/structs.go +++ b/structs.go @@ -1496,6 +1496,7 @@ type TypeValidation struct { ExecutionId string `json:"execution_id" datastore:"execution_id"` NodeId string `json:"node_id" datastore:"node_id"` + TotalProblems int `json:"total_problems" datastore:"total_problems"` Problems []ValidationProblem `json:"errors" datastore:"errors"` SubflowApps []ValidationProblem `json:"subflow_apps" datastore:"subflow_apps"` }