-
Notifications
You must be signed in to change notification settings - Fork 291
/
agent_grpc_stats.go
45 lines (38 loc) · 1.25 KB
/
agent_grpc_stats.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
package agent
import (
"fmt"
"sync"
"github.com/chrislusf/gleam/pb"
)
var (
statsChanMap = make(map[string]chan *pb.ExecutionStat)
statsChanMapRWMutex sync.Mutex
)
func getStatsChan(flowHashCode uint32, stepId int32, taskId int32) chan *pb.ExecutionStat {
key := fmt.Sprintf("%d-%d-%d", flowHashCode, stepId, taskId)
statsChanMapRWMutex.Lock()
defer statsChanMapRWMutex.Unlock()
return statsChanMap[key]
}
func deleteStatsChanByInstructionSet(instructionSet *pb.InstructionSet) {
deleteStatsChan(instructionSet.FlowHashCode,
instructionSet.Instructions[0].GetStepId(),
instructionSet.Instructions[0].GetTaskId())
}
func deleteStatsChan(flowHashCode uint32, stepId int32, taskId int32) {
key := fmt.Sprintf("%d-%d-%d", flowHashCode, stepId, taskId)
statsChanMapRWMutex.Lock()
defer statsChanMapRWMutex.Unlock()
delete(statsChanMap, key)
}
func createStatsChanByInstructionSet(instructionSet *pb.InstructionSet) chan *pb.ExecutionStat {
statsChan := make(chan *pb.ExecutionStat)
key := fmt.Sprintf("%d-%d-%d",
instructionSet.FlowHashCode,
instructionSet.Instructions[0].GetStepId(),
instructionSet.Instructions[0].GetTaskId())
statsChanMapRWMutex.Lock()
defer statsChanMapRWMutex.Unlock()
statsChanMap[key] = statsChan
return statsChan
}