MCPcopy Index your code
hub / github.com/GoEdgeLab/EdgeNode / Loop

Method Loop

internal/nodes/task_sync_api_nodes.go:63–127  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

61}
62
63func (this *SyncAPINodesTask) Loop() error {
64 // 如果有节点定制的API节点地址
65 var hasCustomizedAPINodeAddrs = sharedNodeConfig != nil && len(sharedNodeConfig.APINodeAddrs) > 0
66
67 config, err := configs.LoadAPIConfig()
68 if err != nil {
69 return err
70 }
71
72 // 是否禁止自动升级
73 if config.RPCDisableUpdate {
74 return nil
75 }
76
77 var tr = trackers.Begin("SYNC_API_NODES")
78 defer tr.End()
79
80 // 获取所有可用的节点
81 rpcClient, err := rpc.SharedRPC()
82 if err != nil {
83 return err
84 }
85 resp, err := rpcClient.APINodeRPC.FindAllEnabledAPINodes(rpcClient.Context(), &pb.FindAllEnabledAPINodesRequest{})
86 if err != nil {
87 return err
88 }
89
90 var newEndpoints = []string{}
91 for _, node := range resp.ApiNodes {
92 if !node.IsOn {
93 continue
94 }
95 newEndpoints = append(newEndpoints, node.AccessAddrs...)
96 }
97
98 // 和现有的对比
99 if utils.EqualStrings(newEndpoints, config.RPCEndpoints) {
100 return nil
101 }
102
103 // 测试是否有API节点可用
104 var hasOk = rpcClient.TestEndpoints(newEndpoints)
105 if !hasOk {
106 return nil
107 }
108
109 // 修改RPC对象配置
110 config.RPCEndpoints = newEndpoints
111
112 // 更新当前RPC
113 if !hasCustomizedAPINodeAddrs {
114 err = rpcClient.UpdateConfig(config)
115 if err != nil {
116 return err
117 }
118 }
119
120 // 保存到文件

Callers 1

StartMethod · 0.95

Calls 9

LoadAPIConfigFunction · 0.92
BeginFunction · 0.92
SharedRPCFunction · 0.92
EqualStringsFunction · 0.92
ContextMethod · 0.80
TestEndpointsMethod · 0.80
UpdateConfigMethod · 0.80
WriteFileMethod · 0.80
EndMethod · 0.45

Tested by

no test coverage detected