Skip to content

Commit e61d53e

Browse files
committed
fix: sometimes query gameSummary failed bug
add: query gameSummary rate limiter
1 parent c457939 commit e61d53e

File tree

7 files changed

+24
-9
lines changed

7 files changed

+24
-9
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ build: cmd/hh-lol-prophet/main.go
88
-X hh_lol_prophet.Commit=$(GIT_COMMIT) \
99
-X hh_lol_prophet.BuildTime=$(BUILD_TIME) \
1010
-X hh_lol_prophet.BuildUser=$(BUILD_USER) \
11-
" -o bin/lol对局先知.exe cmd/hh-lol-prophet/main.go
11+
" -o bin/hh-lol-prophet.exe cmd/hh-lol-prophet/main.go
1212
doc: cmd/hh-lol-prophet/main.go
1313
swag init -g .\cmd\hh-lol-prophet\main.go
1414
clean: bin/
1515
@rm -rf bin/*
1616
upx : cmd/hh-lol-prophet/main.go
1717
make build
18-
upx -9 ./bin/lol对局先知.exe
18+
upx -9 ./bin/hh-lol-prophet.exe

conf/AppConf.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ type (
2020
CalcScore CalcScoreConf `json:"calcScore" required:"true"`
2121
}
2222
SentryConf struct {
23-
Enabled bool `json:"enabled" default:"false"`
23+
Enabled bool `json:"enabled" default:"false" env:"enableSentry"`
2424
Dsn string `json:"dsn"`
2525
}
2626
PProfConf struct {

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,18 @@ require (
1313
go.uber.org/zap v1.21.0
1414
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
1515
golang.org/x/sys v0.0.0-20220209214540-3681064d5158
16+
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8
1617
gopkg.in/natefinch/lumberjack.v2 v2.0.0
1718
)
1819

1920
require (
2021
github.com/BurntSushi/toml v1.0.0 // indirect
22+
github.com/avast/retry-go v3.0.0+incompatible // indirect
2123
github.com/go-ole/go-ole v1.2.6 // indirect
2224
github.com/kr/pretty v0.3.0 // indirect
2325
github.com/rogpeppe/go-internal v1.8.0 // indirect
2426
go.uber.org/atomic v1.9.0 // indirect
2527
go.uber.org/multierr v1.7.0 // indirect
26-
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8 // indirect
2728
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
2829
gopkg.in/yaml.v2 v2.4.0 // indirect
2930
)

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ github.com/Joker/hpp v1.0.0/go.mod h1:8x5n+M1Hp5hC0g8okX3sR3vFQwynaX/UgSOM9MeBKz
88
github.com/Shopify/goreferrer v0.0.0-20181106222321-ec9c9a553398/go.mod h1:a1uqRtAwp2Xwc6WNPJEufxJ7fx3npB4UV/JOLmbu5I0=
99
github.com/ajg/form v1.5.1/go.mod h1:uL1WgH+h2mgNtvBq0339dVnzXdBETtL2LeUXaIv25UY=
1010
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
11+
github.com/avast/retry-go v3.0.0+incompatible h1:4SOWQ7Qs+oroOTQOYnAHqelpCO0biHSxpiH9JdtuBj0=
12+
github.com/avast/retry-go v3.0.0+incompatible/go.mod h1:XtSnn+n/sHqQIpZ10K1qAevBhOOCWBLXXy3hyiqqBrY=
1113
github.com/aymerick/raymond v2.0.3-0.20180322193309-b565731e1464+incompatible/go.mod h1:osfaiScAUVup+UC9Nfq76eWqDhXlp+4UYaA8uhTBO6g=
1214
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
1315
github.com/benbjohnson/clock v1.1.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA=

prophet.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,9 @@ func (p Prophet) initGameFlowMonitor(port int, authPwd string) error {
143143
return err
144144
}
145145
p.lcuActive = true
146-
// lcu.ChampionSelectStart()
146+
// if global.IsDevMode() {
147+
// lcu.ChampionSelectStart()
148+
// }
147149
defer c.Close()
148150
_ = c.WriteMessage(websocket.TextMessage, []byte("[5, \"OnJsonApiEvent\"]"))
149151
for {

services/lcu/api.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@ type (
424424
} `json:"timeline"`
425425
}
426426
GameSummary struct {
427+
CommonResp
427428
GameCreation int64 `json:"gameCreation"`
428429
GameCreationDate time.Time `json:"gameCreationDate"`
429430
GameDuration int `json:"gameDuration"`
@@ -478,7 +479,7 @@ const (
478479
)
479480

480481
var (
481-
queryGameSummaryLimiter = rate.NewLimiter(rate.Every(time.Second/40), 40)
482+
queryGameSummaryLimiter = rate.NewLimiter(rate.Every(time.Second/50), 50)
482483
)
483484

484485
// 获取当前召唤师
@@ -628,5 +629,8 @@ func QueryGameSummary(gameID int64) (*GameSummary, error) {
628629
logger.Info("查询对局详情失败", zap.Error(err))
629630
return nil, err
630631
}
632+
if data.CommonResp.ErrorCode != "" {
633+
return nil, errors.New(fmt.Sprintf("查询对局详情失败 :%s ,gameID: %d", data.CommonResp.Message, gameID))
634+
}
631635
return data, nil
632636
}

services/lcu/app.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"sync"
88
"time"
99

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

0 commit comments

Comments
 (0)