Commit d41c21a7 authored by 陈子龙's avatar 陈子龙

主机状态检测 fix

parent 9b36b44b
......@@ -456,21 +456,25 @@ func (h *HostManageSvc) ListStateHostManage(req request.StateHostManageReq) (err
// 使用协程批量执行 ping 命令
var wg sync.WaitGroup
var lock sync.Mutex
wg.Add(len(hostManageList))
successHost := make([]int, 0)
fail := make([]int, 0)
for i := 0; i < len(hostManageList); i++ {
go func() {
i = i
go func(i int) {
//修改状态
connStatus := StatusDetection(hostManageList[i].Ip)
if connStatus == 1 {
lock.Lock()
fail = append(fail, hostManageList[i].Id)
lock.Unlock()
} else {
lock.Lock()
successHost = append(successHost, hostManageList[i].Id)
lock.Unlock()
}
wg.Done()
}()
defer wg.Done()
}(i)
}
wg.Wait()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment