-
Notifications
You must be signed in to change notification settings - Fork 202
/
activities.go
62 lines (53 loc) · 1.41 KB
/
activities.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
package safe_message_handler
import (
"context"
"strconv"
"time"
"go.temporal.io/sdk/activity"
)
type (
AssignNodesToJobInput struct {
Nodes []string
JobName string
}
FindBadNodesInput struct {
NodesToCheck map[string]struct{}
}
UnassignNodesForJobInput struct {
Nodes []string
JobName string
}
)
func AssignNodesToJobsActivity(ctx context.Context, input AssignNodesToJobInput) error {
logger := activity.GetLogger(ctx)
logger.Info("Deallocating nodes to job", "nodes", input.Nodes, "job", input.JobName)
time.Sleep(time.Millisecond * 1)
return nil
}
func UnassignNodesForJobActivity(ctx context.Context, input UnassignNodesForJobInput) error {
logger := activity.GetLogger(ctx)
logger.Info("Unassigning nodes from job", "nodes", input.Nodes, "job", input.JobName)
time.Sleep(time.Millisecond * 1)
return nil
}
func FindBadNodesActivity(ctx context.Context, input FindBadNodesInput) (map[string]struct{}, error) {
time.Sleep(time.Millisecond * 1)
logger := activity.GetLogger(ctx)
badNodes := make(map[string]struct{})
for node := range input.NodesToCheck {
i, err := strconv.Atoi(node)
if err != nil {
logger.Error("Failed to convert node to int", "node", node)
return nil, err
}
if i%5 == 0 {
badNodes[node] = struct{}{}
}
}
if len(badNodes) > 0 {
logger.Info("Found bad node", "nodes", badNodes)
} else {
logger.Info("No new bad nodes found.")
}
return badNodes, nil
}