/
execution_utils.go
67 lines (54 loc) · 1.6 KB
/
execution_utils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package orchestrator
import (
"encoding/json"
"fmt"
"time"
"github.com/APITeamLimited/globe-test/lib"
"github.com/APITeamLimited/globe-test/orchestrator/libOrch"
"github.com/gorilla/websocket"
)
func abortChildJobs(gs libOrch.BaseGlobalState, childJobs map[string]libOrch.ChildJobDistribution) error {
cancelMessage := lib.JobUserUpdate{
UpdateType: "CANCEL",
}
marshalledCancelMessage, err := json.Marshal(cancelMessage)
if err != nil {
return err
}
stringMarshalledCancelMessage := string(marshalledCancelMessage)
for _, jobDistribution := range childJobs {
for _, childJob := range jobDistribution.ChildJobs {
if childJob.WorkerConnection == nil {
continue
}
eventMessage := lib.EventMessage{
Variant: lib.CHILD_USER_UPDATE,
Data: stringMarshalledCancelMessage,
}
marshalledEvent, err := json.Marshal(eventMessage)
if err != nil {
fmt.Println("Error marshalling event message", err)
continue
}
childJob.ConnWriteMutex.Lock()
sendError := childJob.WorkerConnection.WriteMessage(websocket.TextMessage, marshalledEvent)
childJob.ConnWriteMutex.Unlock()
if sendError != nil {
continue
}
}
}
return err
}
func abortAndFailAll(gs libOrch.BaseGlobalState, childJobs map[string]libOrch.ChildJobDistribution, err error) (string, error) {
libOrch.UpdateStatus(gs, "FAILURE")
abortChildJobs(gs, childJobs)
// Send messages again in case they were not received in 10s and 30s
go func() {
time.Sleep(10 * time.Second)
abortChildJobs(gs, childJobs)
time.Sleep(20 * time.Second)
abortChildJobs(gs, childJobs)
}()
return "FAILURE", err
}