MCPcopy Create free account
hub / github.com/crossjoin-io/crossjoin / postTasksResult

Method postTasksResult

api/api_tasks_result.go:9–120  ·  view source on GitHub ↗
(_ http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

7)
8
9func (api *API) postTasksResult(_ http.ResponseWriter, r *http.Request) Response {
10 result := TaskResult{}
11 err := json.NewDecoder(r.Body).Decode(&result)
12 if err != nil {
13 log.Println(err)
14 return Response{
15 OK: false,
16 Status: http.StatusBadRequest,
17 }
18 }
19 if result.Output == nil {
20 result.Output = map[string]interface{}{}
21 }
22 marshaledOutput, err := json.Marshal(result.Output)
23 if err != nil {
24 log.Println(err)
25 return Response{
26 OK: false,
27 Status: http.StatusBadRequest,
28 }
29 }
30 _, err = api.db.Exec("update tasks set completed_at = datetime('now'), success = $1, output = $2, stdout = $3, stderr = $4 where id = $5",
31 result.OK, marshaledOutput, result.Stdout, result.Stderr, result.ID)
32 if err != nil {
33 log.Println(err)
34 return Response{
35 OK: false,
36 Status: http.StatusInternalServerError,
37 Error: err.Error(),
38 }
39 }
40
41 // Now we need to schedule the next task.
42 workflowRunID := ""
43 workflowTaskID := ""
44 err = api.db.QueryRow("select workflow_run_id, workflow_task_id from tasks where id = $1", result.ID).
45 Scan(&workflowRunID, &workflowTaskID)
46 if err != nil {
47 log.Println(err)
48 return Response{
49 OK: false,
50 Status: http.StatusInternalServerError,
51 Error: err.Error(),
52 }
53 }
54 hash := ""
55 workflowID := ""
56 err = api.db.QueryRow("select config_hash, workflow_id from workflow_runs where id = $1", workflowRunID).Scan(&hash, &workflowID)
57 if err != nil {
58 log.Println(err)
59 return Response{
60 OK: false,
61 Status: http.StatusInternalServerError,
62 Error: err.Error(),
63 }
64 }
65
66 // If the task wasn't a success, fail the workflow run.

Callers

nothing calls this directly

Calls 3

CompleteWorkflowRunMethod · 0.95
GetWorkflowMethod · 0.95
ScheduleTaskMethod · 0.95

Tested by

no test coverage detected