()
| 93 | } |
| 94 | |
| 95 | func (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 | |
| 148 | func (this *HTTPCacheTaskManager) PushTaskKeys(keys []string) { |
| 149 | select { |
no test coverage detected