Commit 87e9e94f authored by 陈子龙's avatar 陈子龙

导出异常主机 fix

parent 4e5002f5
......@@ -14,6 +14,7 @@ import (
"gitlab.wodcloud.com/smart-operation/so-operation-api/src/pkg/beagle/resp"
"os/exec"
"strings"
"sync"
"time"
)
......@@ -453,23 +454,61 @@ func (h *HostManageSvc) ListStateHostManage(req request.StateHostManageReq) (err
return
}
fmt.Println("开始:")
for _, v := range hostManageList {
// 使用协程批量执行 ping 命令
var wg sync.WaitGroup
wg.Add(len(hostManageList))
successHost := make([]int, 0)
fail := make([]int, 0)
for i := 0; i < len(hostManageList); i++ {
go func() {
//修改状态
connStatus := StatusDetection(v.Ip)
hostManageListConn := entity.HostManageList{
ConnStatus: connStatus,
connStatus := StatusDetection(hostManageList[i].Ip)
if connStatus == 1 {
fail = append(fail, hostManageList[i].Id)
} else {
successHost = append(successHost, hostManageList[i].Id)
}
wg.Done()
}()
}
wg.Wait()
_, err = session.Table("host_manage_list").Where("is_delete = 0 AND id = ?", v.Id).
Cols("conn_status").Update(&hostManageListConn)
// 批量更新主机连接状态-成功
_, err = session.Table("host_manage_list").Where("is_delete = 0").In("id", successHost).
Cols("conn_status").Update(&entity.HostManageList{
ConnStatus: 0,
})
if err != nil {
err = resp.DbUpdateError.WithError(err)
session.Rollback()
return
}
// 批量更新主机连接状态-失败
_, err = session.Table("host_manage_list").Where("is_delete = 0").In("id", fail).
Cols("conn_status").Update(&entity.HostManageList{
ConnStatus: 1,
})
if err != nil {
err = resp.DbUpdateError.WithError(err)
session.Rollback()
return
}
fmt.Println("结束")
//for _, v := range hostManageList {
// //修改状态
// connStatus := StatusDetection(v.Ip)
// hostManageListConn := entity.HostManageList{
// ConnStatus: connStatus,
// }
//
// _, err = session.Table("host_manage_list").Where("is_delete = 0 AND id = ?", v.Id).
// Cols("conn_status").Update(&hostManageListConn)
// if err != nil {
// err = resp.DbUpdateError.WithError(err)
// session.Rollback()
// return
// }
//}
session.Commit()
return
}
......
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