feat 模块增加after start
This commit is contained in:
11
app/app.go
11
app/app.go
@@ -8,6 +8,7 @@ import (
|
|||||||
"git.hlsq.asia/mmorpg/service-qgdzs/config"
|
"git.hlsq.asia/mmorpg/service-qgdzs/config"
|
||||||
"git.hlsq.asia/mmorpg/service-qgdzs/internal/grpc_server"
|
"git.hlsq.asia/mmorpg/service-qgdzs/internal/grpc_server"
|
||||||
"github.com/judwhite/go-svc"
|
"github.com/judwhite/go-svc"
|
||||||
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Program struct {
|
type Program struct {
|
||||||
@@ -39,8 +40,16 @@ func (p *Program) Init(_ svc.Environment) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *Program) Start() error {
|
func (p *Program) Start() error {
|
||||||
|
ready := &sync.WaitGroup{}
|
||||||
|
ready.Add(len(p.moduleList))
|
||||||
for _, m := range p.moduleList {
|
for _, m := range p.moduleList {
|
||||||
if err := m.Start(); err != nil {
|
if err := m.Start(ready); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ready.Wait()
|
||||||
|
for _, m := range p.moduleList {
|
||||||
|
if err := m.AfterStart(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
13
app/base.go
13
app/base.go
@@ -10,6 +10,7 @@ import (
|
|||||||
|
|
||||||
// ModuleBase 基础模块,或者一些零散的模块
|
// ModuleBase 基础模块,或者一些零散的模块
|
||||||
type ModuleBase struct {
|
type ModuleBase struct {
|
||||||
|
module.DefaultModule
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *ModuleBase) Init() error {
|
func (m *ModuleBase) Init() error {
|
||||||
@@ -24,15 +25,3 @@ func (m *ModuleBase) Init() error {
|
|||||||
utils.InitSnowflake(int64(rand.Intn(1000)))
|
utils.InitSnowflake(int64(rand.Intn(1000)))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *ModuleBase) Start() error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *ModuleBase) Stop() error {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *ModuleBase) Bind(_ ...any) module.Module {
|
|
||||||
return m
|
|
||||||
}
|
|
||||||
|
|||||||
2
go.mod
2
go.mod
@@ -3,7 +3,7 @@ module git.hlsq.asia/mmorpg/service-qgdzs
|
|||||||
go 1.24.0
|
go 1.24.0
|
||||||
|
|
||||||
require (
|
require (
|
||||||
git.hlsq.asia/mmorpg/service-common v0.0.0-20260117160658-22d48542a852
|
git.hlsq.asia/mmorpg/service-common v0.0.0-20260120040718-1edebb439c58
|
||||||
github.com/judwhite/go-svc v1.2.1
|
github.com/judwhite/go-svc v1.2.1
|
||||||
google.golang.org/grpc v1.77.0
|
google.golang.org/grpc v1.77.0
|
||||||
gorm.io/gen v0.3.27
|
gorm.io/gen v0.3.27
|
||||||
|
|||||||
4
go.sum
4
go.sum
@@ -1,7 +1,7 @@
|
|||||||
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
|
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
|
||||||
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
|
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
|
||||||
git.hlsq.asia/mmorpg/service-common v0.0.0-20260117160658-22d48542a852 h1:ehZ54MgGL3CO7KKDPxybFabIXxiQud1TGMcKjrSTcnw=
|
git.hlsq.asia/mmorpg/service-common v0.0.0-20260120040718-1edebb439c58 h1:Bgn3rrISGqzyNA4ax5o4tiTy3tK3QcM/+tCr80fOBhE=
|
||||||
git.hlsq.asia/mmorpg/service-common v0.0.0-20260117160658-22d48542a852/go.mod h1:Dazg+4woCv9Jk7jgT2qUSGWhZOXx/0WYfJO+FCUDyhw=
|
git.hlsq.asia/mmorpg/service-common v0.0.0-20260120040718-1edebb439c58/go.mod h1:Dazg+4woCv9Jk7jgT2qUSGWhZOXx/0WYfJO+FCUDyhw=
|
||||||
github.com/BurntSushi/toml v1.2.0 h1:Rt8g24XnyGTyglgET/PRUNlrUeu9F5L+7FilkXfZgs0=
|
github.com/BurntSushi/toml v1.2.0 h1:Rt8g24XnyGTyglgET/PRUNlrUeu9F5L+7FilkXfZgs0=
|
||||||
github.com/BurntSushi/toml v1.2.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
|
github.com/BurntSushi/toml v1.2.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
|
||||||
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
|
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
|
||||||
|
|||||||
@@ -2,9 +2,27 @@ package grpc_server
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"git.hlsq.asia/mmorpg/service-common/db/redis"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 答题总数排行榜
|
||||||
|
// 正确数量排行榜
|
||||||
|
// 正确率排行榜
|
||||||
|
// 错误数量排行榜
|
||||||
|
// 错误率排行榜
|
||||||
|
|
||||||
|
var (
|
||||||
|
scriptUpdateSha1 string
|
||||||
|
scriptUpdate = `
|
||||||
|
local key = KEYS[1]
|
||||||
|
`
|
||||||
)
|
)
|
||||||
|
|
||||||
// UpdateLeaderboard 更新排行榜
|
// UpdateLeaderboard 更新排行榜
|
||||||
func (s *Server) UpdateLeaderboard(ctx context.Context) error {
|
func (s *Server) UpdateLeaderboard(ctx context.Context) error {
|
||||||
|
if scriptUpdateSha1 == "" {
|
||||||
|
scriptUpdateSha1 = redis.GetClient().ScriptLoad(ctx, scriptUpdate).Val()
|
||||||
|
}
|
||||||
|
redis.GetClient().EvalSha(ctx, scriptUpdateSha1, []string{"key"}, "value")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user