工具心跳处理

This commit is contained in:
wh_zcy 2023-03-10 15:04:27 +08:00
parent 795e534105
commit 3a6de14d83
7 changed files with 31 additions and 32 deletions

View File

@ -4,5 +4,5 @@ Website = "http://legu.cc"
Icon = "app.png" Icon = "app.png"
Name = "RobotGUI" Name = "RobotGUI"
ID = "cc.legu.app" ID = "cc.legu.app"
Version = "1.2.13" Version = "1.2.15"
Build = 43 Build = 49

View File

@ -11,14 +11,15 @@ import (
) )
func BuildSecStr(sid, account string) string { func BuildSecStr(sid, account string) string {
now := time.Now().Unix()
jsonByte, _ := jsoniter.Marshal(&model.LoginParam{ jsonByte, _ := jsoniter.Marshal(&model.LoginParam{
Account: account, Account: account,
ServerId: sid, ServerId: sid,
TimeStamp: time.Now().Unix(), TimeStamp: now,
}) })
jsonBase64 := utils.Base64Encode(jsonByte) jsonBase64 := utils.Base64Encode(jsonByte)
// log.Printf("client base64:%s", jsonBase64) // log.Printf("client base64:%s", jsonBase64)
clientMd5key := util.Md5(jsonBase64) clientMd5key := util.Md5(jsonBase64)
// log.Printf("client md5:%s", clientMd5key) // logrus.Debugf("client md5:%s", clientMd5key)
return fmt.Sprintf("CE:%s%s", clientMd5key, jsonBase64) return fmt.Sprintf("CE:%s%s", clientMd5key, jsonBase64)
} }

View File

@ -54,18 +54,6 @@ func (c *ConnServiceImpl) WsConnect(wsUrl string) error {
return err return err
} }
c.ws = ws c.ws = ws
go func() {
timer := time.NewTimer(2 * time.Second)
for {
timer.Reset(2 * time.Second)
<-timer.C
if err := c.ws.WriteMessage(websocket.PingMessage, []byte{}); err != nil {
c.obs.Notify(observer.EVENT_PING, err)
break
}
}
}()
return nil return nil
} }
@ -80,6 +68,11 @@ func (c *ConnServiceImpl) HttpConnect(url string) ([]byte, error) {
// listener push // listener push
func (c *ConnServiceImpl) ListenerPush() { func (c *ConnServiceImpl) ListenerPush() {
defer func() {
if err := recover(); err != nil {
logrus.Errorf("listenerPush err: %v", err)
}
}()
go func() { go func() {
for { for {
// time.Sleep(time.Millisecond * 200) // time.Sleep(time.Millisecond * 200)

View File

@ -62,7 +62,7 @@ func (p *PttServiceImpl) SendToClient(mainType, subType string, rsp proto.Messag
msg.Sec = common.BuildSecStr(p.user.DbUser.Sid, p.user.DbUser.Binduid) msg.Sec = common.BuildSecStr(p.user.DbUser.Sid, p.user.DbUser.Binduid)
now := time.Now() now := time.Now()
if err = p.connService.SendMsg(msg, rsp); err != nil { if err = p.connService.SendMsg(msg, rsp); err != nil {
logrus.WithField("err", err).Error(err) logrus.WithField("发送错误:", err).Error(err)
return err return err
} }
p.obs.Notify(observer.EVENT_RST, now) p.obs.Notify(observer.EVENT_RST, now)
@ -88,11 +88,18 @@ func (p *PttServiceImpl) Login(sid, account string) (code pb.ErrorCode) {
} }
func (p *PttServiceImpl) Ping(sid, account string) { func (p *PttServiceImpl) Ping(sid, account string) {
defer func() {
if err := recover(); err != nil {
logrus.Errorf("Ping sid:%v account:%v err:%v", sid, account, err)
}
}()
head := &pb.UserMessage{MainType: string(comm.ModuleGate), SubType: "heartbeat"} head := &pb.UserMessage{MainType: string(comm.ModuleGate), SubType: "heartbeat"}
head.Sec = common.BuildSecStr(sid, account) head.Sec = common.BuildSecStr(sid, account)
if err := p.connService.SendMsg(head, &pb.GatewayHeartbeatReq{}); err != nil { if err := p.connService.SendMsg(head, &pb.GatewayHeartbeatReq{}); err != nil {
p.obs.Notify(observer.EVENT_PING, err)
return return
} }
// logrus.Debug("Ping")
return return
} }

View File

@ -89,12 +89,6 @@ func (app *appMonitor) monitorlistener() {
OnNotify: func(d interface{}, args ...interface{}) { OnNotify: func(d interface{}, args ...interface{}) {
app.id++ app.id++
data := d.(*model.PushModel) data := d.(*model.PushModel)
//大于50条时清除一次
// if len(app.monitorList.CachedList.Items) >= 50 {
// app.monitorList.Reset()
// }
protocol := fmt.Sprintf("【%s.%s】", data.Msg.MainType, data.Msg.SubType) protocol := fmt.Sprintf("【%s.%s】", data.Msg.MainType, data.Msg.SubType)
app.monitorList.AddItem(common.Item{ app.monitorList.AddItem(common.Item{
Text: fmt.Sprintf("%d - %-50v %-50v %-50v", Text: fmt.Sprintf("%d - %-50v %-50v %-50v",
@ -103,7 +97,6 @@ func (app *appMonitor) monitorlistener() {
}) })
app.monitorList.ItemList.ScrollToBottom() app.monitorList.ItemList.ScrollToBottom()
// common.ShowCanvasTip("收到新的数据推送,请打开[推送]页面")//非常多调式时会导致系统崩溃
}, },
}) })
} }

View File

@ -313,6 +313,7 @@ func (ui *MainWindowImpl) createLoginWin(sid, sname string) {
return return
} }
//ping
go func() { go func() {
timer := time.NewTimer(10 * time.Second) timer := time.NewTimer(10 * time.Second)
for { for {

View File

@ -13,6 +13,7 @@ import (
"os/exec" "os/exec"
"path/filepath" "path/filepath"
"runtime" "runtime"
"time"
"fyne.io/fyne/v2" "fyne.io/fyne/v2"
"fyne.io/fyne/v2/container" "fyne.io/fyne/v2/container"
@ -32,6 +33,7 @@ type HeroZhaomuView struct {
exportFolder *widget.Entry exportFolder *widget.Entry
resultCountLbl *widget.Label resultCountLbl *widget.Label
resultCount int resultCount int
f *os.File
} }
// 打开目录 // 打开目录
@ -136,9 +138,18 @@ func (this *HeroZhaomuView) CreateView(t *model.TestCase) fyne.CanvasObject {
common.ShowTip("请设置导出目录") common.ShowTip("请设置导出目录")
return return
} }
filePath := filepath.Join(this.exportFolder.Text, "result.txt")
var err error
this.f, err = os.OpenFile(filePath, os.O_CREATE|os.O_APPEND|os.O_RDWR, os.ModeAppend|os.ModePerm)
if err != nil {
logrus.Error(err.Error())
return
}
defer this.f.Close()
for i := 0; i < cast.ToInt(loopCount.Text); i++ { for i := 0; i < cast.ToInt(loopCount.Text); i++ {
choukaBtnFunc() choukaBtnFunc()
time.Sleep(time.Millisecond * 100)
} }
} }
@ -189,15 +200,8 @@ func (this *HeroZhaomuView) resListener() {
logrus.Error("unmarshal err") logrus.Error("unmarshal err")
return return
} }
filePath := filepath.Join(this.exportFolder.Text, "result.txt")
f, err := os.OpenFile(filePath, os.O_CREATE|os.O_APPEND|os.O_RDWR, os.ModeAppend|os.ModePerm)
if err != nil {
logrus.Error(err.Error())
return
}
defer f.Close()
write := bufio.NewWriter(f) write := bufio.NewWriter(this.f)
for _, v := range rsp.Data { for _, v := range rsp.Data {
for _, o := range v.Atno { for _, o := range v.Atno {
if o.A == "hero" && o.O != "" && o.T != "" { if o.A == "hero" && o.O != "" && o.T != "" {