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

主机状态检测 fix

parent 9b36b44b
...@@ -456,21 +456,25 @@ func (h *HostManageSvc) ListStateHostManage(req request.StateHostManageReq) (err ...@@ -456,21 +456,25 @@ func (h *HostManageSvc) ListStateHostManage(req request.StateHostManageReq) (err
// 使用协程批量执行 ping 命令 // 使用协程批量执行 ping 命令
var wg sync.WaitGroup var wg sync.WaitGroup
var lock sync.Mutex
wg.Add(len(hostManageList)) wg.Add(len(hostManageList))
successHost := make([]int, 0) successHost := make([]int, 0)
fail := make([]int, 0) fail := make([]int, 0)
for i := 0; i < len(hostManageList); i++ { for i := 0; i < len(hostManageList); i++ {
go func() { go func(i int) {
i = i
//修改状态 //修改状态
connStatus := StatusDetection(hostManageList[i].Ip) connStatus := StatusDetection(hostManageList[i].Ip)
if connStatus == 1 { if connStatus == 1 {
lock.Lock()
fail = append(fail, hostManageList[i].Id) fail = append(fail, hostManageList[i].Id)
lock.Unlock()
} else { } else {
lock.Lock()
successHost = append(successHost, hostManageList[i].Id) successHost = append(successHost, hostManageList[i].Id)
lock.Unlock()
} }
wg.Done() defer wg.Done()
}() }(i)
} }
wg.Wait() 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