Skip to content

Commit

Permalink
fix: sometimes query gameSummary failed bug
Browse files Browse the repository at this point in the history
add: query gameSummary rate limiter
  • Loading branch information
buffge committed Feb 18, 2022
1 parent c457939 commit e61d53e
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 9 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ build: cmd/hh-lol-prophet/main.go
-X hh_lol_prophet.Commit=$(GIT_COMMIT) \
-X hh_lol_prophet.BuildTime=$(BUILD_TIME) \
-X hh_lol_prophet.BuildUser=$(BUILD_USER) \
" -o bin/lol对局先知.exe cmd/hh-lol-prophet/main.go
" -o bin/hh-lol-prophet.exe cmd/hh-lol-prophet/main.go
doc: cmd/hh-lol-prophet/main.go
swag init -g .\cmd\hh-lol-prophet\main.go
clean: bin/
@rm -rf bin/*
upx : cmd/hh-lol-prophet/main.go
make build
upx -9 ./bin/lol对局先知.exe
upx -9 ./bin/hh-lol-prophet.exe
2 changes: 1 addition & 1 deletion conf/AppConf.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type (
CalcScore CalcScoreConf `json:"calcScore" required:"true"`
}
SentryConf struct {
Enabled bool `json:"enabled" default:"false"`
Enabled bool `json:"enabled" default:"false" env:"enableSentry"`
Dsn string `json:"dsn"`
}
PProfConf struct {
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,18 @@ require (
go.uber.org/zap v1.21.0
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
golang.org/x/sys v0.0.0-20220209214540-3681064d5158
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8
gopkg.in/natefinch/lumberjack.v2 v2.0.0
)

require (
github.com/BurntSushi/toml v1.0.0 // indirect
github.com/avast/retry-go v3.0.0+incompatible // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/kr/pretty v0.3.0 // indirect
github.com/rogpeppe/go-internal v1.8.0 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.7.0 // indirect
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ github.com/Joker/hpp v1.0.0/go.mod h1:8x5n+M1Hp5hC0g8okX3sR3vFQwynaX/UgSOM9MeBKz
github.com/Shopify/goreferrer v0.0.0-20181106222321-ec9c9a553398/go.mod h1:a1uqRtAwp2Xwc6WNPJEufxJ7fx3npB4UV/JOLmbu5I0=
github.com/ajg/form v1.5.1/go.mod h1:uL1WgH+h2mgNtvBq0339dVnzXdBETtL2LeUXaIv25UY=
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
github.com/avast/retry-go v3.0.0+incompatible h1:4SOWQ7Qs+oroOTQOYnAHqelpCO0biHSxpiH9JdtuBj0=
github.com/avast/retry-go v3.0.0+incompatible/go.mod h1:XtSnn+n/sHqQIpZ10K1qAevBhOOCWBLXXy3hyiqqBrY=
github.com/aymerick/raymond v2.0.3-0.20180322193309-b565731e1464+incompatible/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g=
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=
Expand Down
4 changes: 3 additions & 1 deletion prophet.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,9 @@ func (p Prophet) initGameFlowMonitor(port int, authPwd string) error {
return err
}
p.lcuActive = true
// lcu.ChampionSelectStart()
// if global.IsDevMode() {
// lcu.ChampionSelectStart()
// }
defer c.Close()
_ = c.WriteMessage(websocket.TextMessage, []byte("[5, \"OnJsonApiEvent\"]"))
for {
Expand Down
6 changes: 5 additions & 1 deletion services/lcu/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ type (
} `json:"timeline"`
}
GameSummary struct {
CommonResp
GameCreation int64 `json:"gameCreation"`
GameCreationDate time.Time `json:"gameCreationDate"`
GameDuration int `json:"gameDuration"`
Expand Down Expand Up @@ -478,7 +479,7 @@ const (
)

var (
queryGameSummaryLimiter = rate.NewLimiter(rate.Every(time.Second/40), 40)
queryGameSummaryLimiter = rate.NewLimiter(rate.Every(time.Second/50), 50)
)

// 获取当前召唤师
Expand Down Expand Up @@ -628,5 +629,8 @@ func QueryGameSummary(gameID int64) (*GameSummary, error) {
logger.Info("查询对局详情失败", zap.Error(err))
return nil, err
}
if data.CommonResp.ErrorCode != "" {
return nil, errors.New(fmt.Sprintf("查询对局详情失败 :%s ,gameID: %d", data.CommonResp.Message, gameID))
}
return data, nil
}
12 changes: 9 additions & 3 deletions services/lcu/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"sync"
"time"

"github.com/avast/retry-go"
"github.com/pkg/errors"
"github.com/real-web-world/hh-lol-prophet/global"
"github.com/real-web-world/hh-lol-prophet/services/lcu/models"
Expand Down Expand Up @@ -41,8 +42,8 @@ func ChampionSelectStart() {
continue
}
}
// if !false {
// summonerIDList = []int64{2965189289, 4014052617, 4015941802, 2613569584655104, 2950744173}
// if !false && global.IsDevMode() {
// summonerIDList = []int64{2964390005, 4103784618, 4132401993, 4118593599, 4019221688}
// // summonerIDList = []int64{4006944917}
// }
logger.Debug("队伍人员列表:", zap.Any("summonerIDList", summonerIDList))
Expand Down Expand Up @@ -145,7 +146,12 @@ func GetUserScore(summonerID int64) (*UserScore, error) {
info.Participants[0].Stats.Assists,
}
g.Go(func() error {
gameSummary, err := QueryGameSummary(info.GameId)
var gameSummary *GameSummary
err = retry.Do(func() error {
var tmpErr error
gameSummary, tmpErr = QueryGameSummary(info.GameId)
return tmpErr
}, retry.Delay(time.Millisecond*10), retry.Attempts(5))
if err != nil {
logger.Error("获取游戏对局详细信息失败", zap.Error(err), zap.Int64("id", info.GameId))
return nil
Expand Down

0 comments on commit e61d53e

Please sign in to comment.