MCPcopy Create free account
hub / github.com/GoEdgeLab/EdgeNode / Loop

Method Loop

internal/nodes/http_cache_task_manager.go:95–146  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

93}
94
95func (this *HTTPCacheTaskManager) Loop() error {
96 rpcClient, err := rpc.SharedRPC()
97 if err != nil {
98 return err
99 }
100
101 resp, err := rpcClient.HTTPCacheTaskKeyRPC.FindDoingHTTPCacheTaskKeys(rpcClient.Context(), &pb.FindDoingHTTPCacheTaskKeysRequest{})
102 if err != nil {
103 // 忽略连接错误
104 if rpc.IsConnError(err) {
105 return nil
106 }
107 return err
108 }
109
110 var keys = resp.HttpCacheTaskKeys
111 if len(keys) == 0 {
112 return nil
113 }
114
115 var pbResults = []*pb.UpdateHTTPCacheTaskKeysStatusRequest_KeyResult{}
116
117 var taskGroup = goman.NewTaskGroup()
118 for _, key := range keys {
119 var taskKey = key
120 taskGroup.Run(func() {
121 processErr := this.processKey(taskKey)
122 var pbResult = &pb.UpdateHTTPCacheTaskKeysStatusRequest_KeyResult{
123 Id: taskKey.Id,
124 NodeClusterId: taskKey.NodeClusterId,
125 Error: "",
126 }
127
128 if processErr != nil {
129 pbResult.Error = processErr.Error()
130 }
131
132 taskGroup.Lock()
133 pbResults = append(pbResults, pbResult)
134 taskGroup.Unlock()
135 })
136 }
137
138 taskGroup.Wait()
139
140 _, err = rpcClient.HTTPCacheTaskKeyRPC.UpdateHTTPCacheTaskKeysStatus(rpcClient.Context(), &pb.UpdateHTTPCacheTaskKeysStatusRequest{KeyResults: pbResults})
141 if err != nil {
142 return err
143 }
144
145 return nil
146}
147
148func (this *HTTPCacheTaskManager) PushTaskKeys(keys []string) {
149 select {

Callers 1

StartMethod · 0.95

Calls 10

processKeyMethod · 0.95
SharedRPCFunction · 0.92
IsConnErrorFunction · 0.92
NewTaskGroupFunction · 0.92
ContextMethod · 0.80
RunMethod · 0.45
ErrorMethod · 0.45
LockMethod · 0.45
UnlockMethod · 0.45
WaitMethod · 0.45

Tested by

no test coverage detected