上传压测机器人代码

This commit is contained in:
liwei1dao 2023-08-23 19:01:10 +08:00
parent 7835ad53a1
commit 3db40119a8
3 changed files with 8 additions and 9 deletions

View File

@ -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 {

View File

@ -9,6 +9,7 @@ type (
Options struct {
modules.Options
ServerAddr string //服务地址
ServerID string //服务ID
RobotTotalNum int32 //机器人总数
RobotSingleNum int32 //单词机器人进入数量
Intervals int32 //间隔时间 单位秒

View File

@ -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 {