上传压测机器人代码
This commit is contained in:
parent
7835ad53a1
commit
3db40119a8
@ -8,6 +8,7 @@ import (
|
|||||||
"go_dreamfactory/pb"
|
"go_dreamfactory/pb"
|
||||||
"go_dreamfactory/sys/configure"
|
"go_dreamfactory/sys/configure"
|
||||||
cfg "go_dreamfactory/sys/configure/structs"
|
cfg "go_dreamfactory/sys/configure/structs"
|
||||||
|
"time"
|
||||||
|
|
||||||
"google.golang.org/protobuf/proto"
|
"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) {
|
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 {
|
switch stype {
|
||||||
case "info":
|
case "info":
|
||||||
resp := message.(*pb.WTaskInfoResp)
|
resp := message.(*pb.WTaskInfoResp)
|
||||||
@ -51,6 +53,7 @@ func (this *ModuleRobot_WTask) Receive(robot IRobot, stype string, message proto
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
this.progress = append(this.progress, resp.Progress)
|
||||||
break
|
break
|
||||||
case "finish":
|
case "finish":
|
||||||
resp := message.(*pb.WTaskFinishResp)
|
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)
|
this.info.Accepts = append(this.info.Accepts, v.Tid)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if this.state == 1 {
|
|
||||||
this.change <- true
|
|
||||||
}
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
return
|
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 !"})
|
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
|
break locp
|
||||||
}
|
}
|
||||||
this.change = make(chan bool)
|
|
||||||
this.state = 1
|
|
||||||
if err = robot.DoTask(tconf, cconf, module); err != nil {
|
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()})
|
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
|
break locp
|
||||||
}
|
}
|
||||||
<-this.change //等待任务进度更新
|
time.Sleep(time.Second)
|
||||||
this.state = 0
|
|
||||||
continue
|
continue
|
||||||
} else { //任务已完成直接完成
|
} else { //任务已完成直接完成
|
||||||
if _, errdata = robot.SendMessage("wtask", "finish", &pb.WTaskFinishReq{Tid: tconf.Key}); errdata != nil {
|
if _, errdata = robot.SendMessage("wtask", "finish", &pb.WTaskFinishReq{Tid: tconf.Key}); errdata != nil {
|
||||||
|
@ -9,6 +9,7 @@ type (
|
|||||||
Options struct {
|
Options struct {
|
||||||
modules.Options
|
modules.Options
|
||||||
ServerAddr string //服务地址
|
ServerAddr string //服务地址
|
||||||
|
ServerID string //服务ID
|
||||||
RobotTotalNum int32 //机器人总数
|
RobotTotalNum int32 //机器人总数
|
||||||
RobotSingleNum int32 //单词机器人进入数量
|
RobotSingleNum int32 //单词机器人进入数量
|
||||||
Intervals int32 //间隔时间 单位秒
|
Intervals int32 //间隔时间 单位秒
|
||||||
|
@ -58,8 +58,8 @@ func (this *robotmgrComp) createRobot(index int32) {
|
|||||||
)
|
)
|
||||||
robot = &Robot{
|
robot = &Robot{
|
||||||
index: index,
|
index: index,
|
||||||
account: fmt.Sprintf("test%d", index),
|
account: fmt.Sprintf("ft_%d", index),
|
||||||
serverId: "df01",
|
serverId: this.module.options.ServerID,
|
||||||
pipeline: this.module.options.Pipeline,
|
pipeline: this.module.options.Pipeline,
|
||||||
}
|
}
|
||||||
if err = robot.Init(this.module.options.ServerAddr, robot); err != nil {
|
if err = robot.Init(this.module.options.ServerAddr, robot); err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user