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

导出异常主机 fix

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