From 4f77a236123c02a56407b404bff07fa71a05fbba Mon Sep 17 00:00:00 2001 From: Frikky Date: Sun, 23 Mar 2025 20:37:22 +0100 Subject: [PATCH] Added 'wait' query to execute workflow and optimized heavily how fast they start to run --- backend/go-app/walkoff.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/backend/go-app/walkoff.go b/backend/go-app/walkoff.go index 1878d1b0..d2316b5d 100755 --- a/backend/go-app/walkoff.go +++ b/backend/go-app/walkoff.go @@ -1056,7 +1056,7 @@ func handleExecution(id string, workflow shuffle.Workflow, request *http.Request ctx := context.Background() if workflow.ID == "" || workflow.ID != id { - tmpworkflow, err := shuffle.GetWorkflow(ctx, id) + tmpworkflow, err := shuffle.GetWorkflow(ctx, id, true) if err != nil { //log.Printf("[WARNING] Failed getting the workflow locally (execution setup): %s", err) return shuffle.WorkflowExecution{}, "Failed getting workflow", err @@ -1905,7 +1905,7 @@ func executeWorkflow(resp http.ResponseWriter, request *http.Request) { log.Printf("[INFO] Inside execute workflow for ID %s", fileId) ctx := context.Background() - workflow, err := shuffle.GetWorkflow(ctx, fileId) + workflow, err := shuffle.GetWorkflow(ctx, fileId, true) if err != nil && workflow.ID == "" { log.Printf("[WARNING] Failed getting the workflow locally (execute workflow): %s", err) resp.WriteHeader(401) @@ -1962,6 +1962,20 @@ func executeWorkflow(resp http.ResponseWriter, request *http.Request) { } resp.WriteHeader(200) + + // Check for "wait" query if it's true + wait, waitok := request.URL.Query()["wait"] + if waitok && wait[0] == "true" { + returnBody := shuffle.HandleRetValidation(ctx, workflowExecution, 1) + returnBytes, err := json.Marshal(returnBody) + if err != nil { + log.Printf("[ERROR] Failed to marshal retStruct in single execution: %s", err) + } + + resp.Write(returnBytes) + return + } + resp.Write([]byte(fmt.Sprintf(`{"success": true, "execution_id": "%s", "authorization": "%s"}`, workflowExecution.ExecutionId, workflowExecution.Authorization))) return }