Added 'wait' query to execute workflow and optimized heavily how fast they start to run

This commit is contained in:
Frikky
2025-03-23 20:37:22 +01:00
parent 83027ab206
commit 4f77a23612
+16 -2
View File
@@ -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
}