From 3db40119a8035564235f1463a4d37983fb9afe08 Mon Sep 17 00:00:00 2001 From: liwei1dao Date: Wed, 23 Aug 2023 19:01:10 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E5=8E=8B=E6=B5=8B=E6=9C=BA?= =?UTF-8?q?=E5=99=A8=E4=BA=BA=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/robot/modulerobot_wtask.go | 12 +++++------- modules/robot/options.go | 1 + modules/robot/robotmgrcomp.go | 4 ++-- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/modules/robot/modulerobot_wtask.go b/modules/robot/modulerobot_wtask.go index 9b56c123b..54d38efea 100644 --- a/modules/robot/modulerobot_wtask.go +++ b/modules/robot/modulerobot_wtask.go @@ -8,6 +8,7 @@ import ( "go_dreamfactory/pb" "go_dreamfactory/sys/configure" cfg "go_dreamfactory/sys/configure/structs" + "time" "google.golang.org/protobuf/proto" ) @@ -26,6 +27,7 @@ func (this *ModuleRobot_WTask) Init() { //接收到消息 func (this *ModuleRobot_WTask) Receive(robot IRobot, stype string, message proto.Message) (err error) { + // log.Debug("[机器人 WTask]", log.Field{Key: "Account", Value: robot.Account()}, log.Field{Key: "message", Value: message}) switch stype { case "info": resp := message.(*pb.WTaskInfoResp) @@ -51,6 +53,7 @@ func (this *ModuleRobot_WTask) Receive(robot IRobot, stype string, message proto break } } + this.progress = append(this.progress, resp.Progress) break case "finish": resp := message.(*pb.WTaskFinishResp) @@ -75,9 +78,6 @@ func (this *ModuleRobot_WTask) Receive(robot IRobot, stype string, message proto this.info.Accepts = append(this.info.Accepts, v.Tid) } } - if this.state == 1 { - this.change <- true - } break } return @@ -128,14 +128,12 @@ locp: log.Error("[Robot DoTask]", log.Field{Key: "ctype", Value: cconf.Type}, log.Field{Key: "conld", Value: cconf.Id}, log.Field{Key: "err", Value: "Not Achieved !"}) break locp } - this.change = make(chan bool) - this.state = 1 + if err = robot.DoTask(tconf, cconf, module); err != nil { log.Error("[Robot DoTask]", log.Field{Key: "task", Value: tconf.Key}, log.Field{Key: "conld", Value: cconf.Id}, log.Field{Key: "err", Value: err.Error()}) break locp } - <-this.change //等待任务进度更新 - this.state = 0 + time.Sleep(time.Second) continue } else { //任务已完成直接完成 if _, errdata = robot.SendMessage("wtask", "finish", &pb.WTaskFinishReq{Tid: tconf.Key}); errdata != nil { diff --git a/modules/robot/options.go b/modules/robot/options.go index 9cc4c8e6d..3845d8517 100644 --- a/modules/robot/options.go +++ b/modules/robot/options.go @@ -9,6 +9,7 @@ type ( Options struct { modules.Options ServerAddr string //服务地址 + ServerID string //服务ID RobotTotalNum int32 //机器人总数 RobotSingleNum int32 //单词机器人进入数量 Intervals int32 //间隔时间 单位秒 diff --git a/modules/robot/robotmgrcomp.go b/modules/robot/robotmgrcomp.go index b59b64bf1..5ffedf7ef 100644 --- a/modules/robot/robotmgrcomp.go +++ b/modules/robot/robotmgrcomp.go @@ -58,8 +58,8 @@ func (this *robotmgrComp) createRobot(index int32) { ) robot = &Robot{ index: index, - account: fmt.Sprintf("test%d", index), - serverId: "df01", + account: fmt.Sprintf("ft_%d", index), + serverId: this.module.options.ServerID, pipeline: this.module.options.Pipeline, } if err = robot.Init(this.module.options.ServerAddr, robot); err != nil {