This commit is contained in:
laodaming 2023-10-10 18:08:58 +08:00
parent a0106e30cc
commit 8cf76c7051
2 changed files with 16 additions and 4 deletions

View File

@ -10,4 +10,8 @@ type Config struct {
SourceMysql string
Auth types.Auth
SourceRabbitMq string
BLMService struct {
Version string
Urls []string
}
}

View File

@ -48,13 +48,21 @@ func (l *TestAiLogic) TestAi(req *types.TestAiReq, userinfo *auth.UserInfo) (res
logx.Error("测试异常:", err)
}
}()
//lenAiHost := len(l.svcCtx.Config.)
lenAiHost := len(l.svcCtx.Config.BLMService.Urls)
if lenAiHost == 0 {
return resp.SetStatusWithMessage(basic.CodeServiceErr, "ai host list is 0")
}
begin := time.Now().UTC().UnixMilli()
errChan := make(chan string)
w := sync.WaitGroup{}
b := -1
for i := 0; i < req.Num; i++ {
w.Add(1)
go func() {
b++
if b > lenAiHost-1 {
b = 0
}
go func(hostIndex int) {
defer func() {
if err := recover(); err != nil {
logx.Error("测试异常2", err)
@ -69,7 +77,7 @@ func (l *TestAiLogic) TestAi(req *types.TestAiReq, userinfo *auth.UserInfo) (res
}
var resultBLM constants.BLMServiceUrlResult
err := curl.NewClient(l.ctx, &curl.Config{
BaseUrl: "http://ai.fusen.3718.cn:8999",
BaseUrl: l.svcCtx.Config.BLMService.Urls[hostIndex],
Url: constants.BLMServiceUrlLogoCombine,
RequireTimeout: time.Second * 15,
}).PostJson(postMap, &resultBLM)
@ -77,7 +85,7 @@ func (l *TestAiLogic) TestAi(req *types.TestAiReq, userinfo *auth.UserInfo) (res
errChan <- err.Error()
return
}
}()
}(b)
}
go func() {
w.Wait()