Loop 单次循环获取数据
()
| 129 | |
| 130 | // Loop 单次循环获取数据 |
| 131 | func (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 添加记录 |
| 177 | func (this *Manager) AddIP(ip string, agentCode string) { |