调整act持久化方案不放在定时任务中
This commit is contained in:
@@ -2,11 +2,12 @@ package boot
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
v1 "github.com/ayflying/utility_go/api/system/v1"
|
||||
"github.com/ayflying/utility_go/service"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/os/gctx"
|
||||
"github.com/gogf/gf/v2/os/gtimer"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -18,17 +19,29 @@ func Boot() (err error) {
|
||||
// 启动计划任务定时器,预防debug工具激活计划任务造成重复执行,此处不执行计划任务
|
||||
//err = service.SystemCron().StartCron()
|
||||
|
||||
//用户活动持久化每小时执行一次
|
||||
service.SystemCron().AddCronV2(v1.CronType_HOUR, func(context.Context) error {
|
||||
go func() {
|
||||
// //用户活动持久化每小时执行一次
|
||||
// service.SystemCron().AddCronV2(v1.CronType_HOUR, func(context.Context) error {
|
||||
// go func() {
|
||||
// err = service.GameKv().SavesV1()
|
||||
// err = service.GameAct().SavesV2()
|
||||
// if err != nil {
|
||||
// g.Log().Error(gctx.New(), err)
|
||||
// }
|
||||
// }()
|
||||
// return nil
|
||||
// }, true)
|
||||
|
||||
//延迟6秒执行定时器
|
||||
gtimer.SetTimeout(ctx, time.Second*10, func(ctx context.Context) {
|
||||
gtimer.SetInterval(ctx, time.Hour*2, func(ctx context.Context) {
|
||||
err = service.GameKv().SavesV1()
|
||||
err = service.GameAct().SavesV2()
|
||||
if err != nil {
|
||||
g.Log().Error(gctx.New(), err)
|
||||
}
|
||||
}()
|
||||
return nil
|
||||
}, true)
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
//初始化自启动方法
|
||||
for _, v := range _func {
|
||||
|
||||
@@ -293,7 +293,7 @@ func (s *sGameAct) Save(ctx context.Context, actId int) (err error) {
|
||||
func (s *sGameAct) SavesV2() (err error) {
|
||||
var ctx = gctx.New()
|
||||
g.Log().Debug(ctx, "开始执行游戏act数据保存了")
|
||||
RunTimeMax = gtime.Now().Add(time.Minute * 30)
|
||||
RunTimeMax = gtime.Now().Add(time.Minute * 60)
|
||||
|
||||
// 使用局部通道替代包级通道,避免并发冲突
|
||||
addChan := make(chan *entity.GameAct, 1000)
|
||||
@@ -783,7 +783,6 @@ func (s *sGameAct) DelCacheKey(ctx context.Context, aid int, uid int64) {
|
||||
g.Log().Error(ctx, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 清空GetRedDot缓存
|
||||
func (s *sGameAct) RefreshGetRedDotCache(uid int64) {
|
||||
|
||||
@@ -76,6 +76,11 @@ type (
|
||||
// Cache2AddChan 批量添加数据库
|
||||
Cache2SqlChan(ctx context.Context, addChan chan *entity.GameAct, updateChan chan *entity.GameAct)
|
||||
// SaveV2Batch 批量保存游戏活动数据 (优化版)
|
||||
//
|
||||
// @Description: 使用批量Redis MGET和批量数据库操作提升性能
|
||||
// @param ctx context.Context: 上下文对象
|
||||
// @param cacheKeys []string: 缓存键列表
|
||||
// @return err error: 返回错误信息
|
||||
SaveV2Batch(ctx context.Context, cacheKeys []string) (err error)
|
||||
// 删除缓存key
|
||||
DelCacheKey(ctx context.Context, aid int, uid int64)
|
||||
|
||||
@@ -17,10 +17,15 @@ type (
|
||||
// @receiver s: sGameKv的实例。
|
||||
// @return err: 错误信息,如果操作成功,则为nil。
|
||||
SavesV1() (err error)
|
||||
// SavesV2Batch 批量保存游戏KV数据 (优化版)
|
||||
SavesV2Batch(ctx context.Context, cacheKeys []string) (err error)
|
||||
// 删除缓存key
|
||||
DelCacheKey(ctx context.Context, uid int64)
|
||||
// SavesV2Batch 批量保存游戏KV数据 (优化版)
|
||||
//
|
||||
// @Description: 使用批量Redis MGET和批量数据库操作提升性能
|
||||
// @param ctx context.Context: 上下文对象
|
||||
// @param cacheKeys []string: 缓存键列表
|
||||
// @return err error: 返回错误信息
|
||||
SavesV2Batch(ctx context.Context, cacheKeys []string) (err error)
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user