Added a way to run worker.go standalone: go run worker.go standalone <execution_id> <authentication> <url>

This commit is contained in:
Frikky
2025-04-05 00:08:03 +02:00
parent 557c39c8fc
commit 04c28b08c7
9 changed files with 363 additions and 177 deletions
+15 -11
View File
@@ -548,7 +548,7 @@ func handleGetWorkflowqueue(resp http.ResponseWriter, request *http.Request) {
resp.Write(newjson)
}
func handleGetStreamResults(resp http.ResponseWriter, request *http.Request) {
func handleGetWorkflowExecutionResult(resp http.ResponseWriter, request *http.Request) {
cors := shuffle.HandleCors(resp, request)
if cors {
return
@@ -679,7 +679,7 @@ func handleGetStreamResults(resp http.ResponseWriter, request *http.Request) {
}
func handleWorkflowQueue(resp http.ResponseWriter, request *http.Request) {
func handleSetWorkflowExecution(resp http.ResponseWriter, request *http.Request) {
cors := shuffle.HandleCors(resp, request)
if cors {
return
@@ -698,20 +698,27 @@ func handleWorkflowQueue(resp http.ResponseWriter, request *http.Request) {
return
}
//log.Printf("Actionresult unmarshal: %s", string(body))
//log.Printf("[DEBUG] Got workflow result from %s of length %d", request.RemoteAddr, len(body))
// Allows override of existing executions.
// This is a way to set them back to 0 results and rerun the
// exact same. Primarily in use for Worker testing of specific workflows.
shouldReset := false
resetString, ok := request.URL.Query()["reset"]
if ok && len(resetString) > 0 {
if resetString[0] == "true" {
shouldReset = true
}
}
ctx := context.Background()
err = shuffle.ValidateNewWorkerExecution(ctx, body)
err = shuffle.ValidateNewWorkerExecution(ctx, body, shouldReset)
if err == nil {
resp.WriteHeader(200)
resp.Write([]byte(fmt.Sprintf(`{"success": true, "reason": "success"}`)))
resp.Write([]byte(fmt.Sprintf(`{"success": true, "reason": "Successfully updated the execution"}`)))
return
} else {
//log.Printf("[DEBUG] Handling other execution variant (subflow?): %s", err)
}
//log.Printf("[DEBUG] Got workflow result from %s of length %d.", request.RemoteAddr, len(body))
var actionResult shuffle.ActionResult
err = json.Unmarshal(body, &actionResult)
if err != nil {
@@ -721,8 +728,6 @@ func handleWorkflowQueue(resp http.ResponseWriter, request *http.Request) {
//return
}
//log.Printf("Received action: %#v", actionResult)
// 1. Get the WorkflowExecution(ExecutionId) from the database
// 2. if ActionResult.Authentication != WorkflowExecution.Authentication -> exit
// 3. Add to and update actionResult in workflowExecution
@@ -3036,7 +3041,6 @@ func executeSingleAction(resp http.ResponseWriter, request *http.Request) {
shouldRerun = true
}
workflowExecution, err := shuffle.PrepareSingleAction(ctx, user, fileId, body, runValidationAction)
debugUrl := fmt.Sprintf("/workflows/%s?execution_id=%s", workflowExecution.Workflow.ID, workflowExecution.ExecutionId)