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

Method Loop

internal/utils/agents/manager.go:131–174  ·  view source on GitHub ↗

Loop 单次循环获取数据

()

Source from the content-addressed store, hash-verified

129
130// Loop 单次循环获取数据
131func (this *Manager) Loop() (hasNext bool, err error) {
132 rpcClient, err := rpc.SharedRPC()
133 if err != nil {
134 return false, err
135 }
136 ipsResp, err := rpcClient.ClientAgentIPRPC.ListClientAgentIPsAfterId(rpcClient.Context(), &pb.ListClientAgentIPsAfterIdRequest{
137 Id: this.lastId,
138 Size: 10000,
139 })
140 if err != nil {
141 return false, err
142 }
143 if len(ipsResp.ClientAgentIPs) == 0 {
144 return false, nil
145 }
146 for _, agentIP := range ipsResp.ClientAgentIPs {
147 if agentIP.ClientAgent == nil {
148 // 设置ID
149 if agentIP.Id > this.lastId {
150 this.lastId = agentIP.Id
151 }
152
153 continue
154 }
155
156 // 写入到数据库
157 err = this.db.InsertAgentIP(agentIP.Id, agentIP.Ip, agentIP.ClientAgent.Code)
158 if err != nil {
159 return false, err
160 }
161
162 // 写入Map
163 this.locker.Lock()
164 this.ipMap[agentIP.Ip] = agentIP.ClientAgent.Code
165 this.locker.Unlock()
166
167 // 设置ID
168 if agentIP.Id > this.lastId {
169 this.lastId = agentIP.Id
170 }
171 }
172
173 return true, nil
174}
175
176// AddIP 添加记录
177func (this *Manager) AddIP(ip string, agentCode string) {

Callers 2

LoopAllMethod · 0.95
TestNewManagerFunction · 0.45

Calls 5

SharedRPCFunction · 0.92
ContextMethod · 0.80
InsertAgentIPMethod · 0.65
LockMethod · 0.45
UnlockMethod · 0.45

Tested by 1

TestNewManagerFunction · 0.36