From bec893d6621a4c1b5974196bf925876c2db03f57 Mon Sep 17 00:00:00 2001 From: dujiashu <929365073@qq.com> Date: Sun, 1 Nov 2020 11:07:17 +0800 Subject: [PATCH] validate hosts unique (#371) * support tt automation by job * format * import order * use map to avoid repetition Co-authored-by: dujiashu --- src/modules/job/http/router_task.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/modules/job/http/router_task.go b/src/modules/job/http/router_task.go index b5d3a50b..bc96a636 100644 --- a/src/modules/job/http/router_task.go +++ b/src/modules/job/http/router_task.go @@ -12,9 +12,9 @@ import ( "github.com/toolkits/pkg/net/httplib" "github.com/toolkits/pkg/slice" + "github.com/didi/nightingale/src/common/address" "github.com/didi/nightingale/src/models" "github.com/didi/nightingale/src/modules/job/config" - "github.com/didi/nightingale/src/common/address" ) type taskForm struct { @@ -658,11 +658,16 @@ func taskRunForTT(c *gin.Context) { dangerous(task.Save(arr, "start")) go func() { + var arr2Map = map[string]int{} + for _, a := range arr { + arr2Map[a] = 1 + } + for { var ( - restHosts []string + restHosts = map[string]int{} ) - for _, h := range arr { + for h, _ := range arr2Map { th, err := models.TaskHostGet(task.Id, h) if err == nil { if th.Status == "killed" { @@ -702,13 +707,14 @@ func taskRunForTT(c *gin.Context) { logger.Errorf("send callback to ticket, err: %v", err) } } else { - restHosts = append(restHosts, h) + restHosts[h] = 1 } } else { logger.Errorf("get task_host err: %v", err) } } - arr = restHosts + + arr2Map = restHosts time.Sleep(time.Second) } }()