保存计划任务调整

This commit is contained in:
ayflying
2025-08-22 17:50:37 +08:00
parent 862a6c8410
commit e781e132ed
3 changed files with 13 additions and 3 deletions

View File

@@ -110,6 +110,7 @@ func (s *sGameAct) Set(uid int64, actId int, data interface{}) (err error) {
func (s *sGameAct) Saves(ctx context.Context) (err error) { func (s *sGameAct) Saves(ctx context.Context) (err error) {
getCache, _ := pkg.Cache("redis").Get(nil, "cron:game_act") getCache, _ := pkg.Cache("redis").Get(nil, "cron:game_act")
g.Log().Debug(ctx, "开始执行游戏act数据保存了")
//如果没有执行过,设置时间戳 //如果没有执行过,设置时间戳
if getCache.Int64() > 0 { if getCache.Int64() > 0 {
return return
@@ -122,8 +123,10 @@ func (s *sGameAct) Saves(ctx context.Context) (err error) {
ActList.Iterator(func(i interface{}) bool { ActList.Iterator(func(i interface{}) bool {
//在时间内允许执行 //在时间内允许执行
if gtime.Now().Before(RunTimeMax) { if gtime.Now().Before(RunTimeMax) {
g.Log().Errorf(ctx, "开始执行游戏act数据保存: act%v", i) g.Log().Debug(ctx, "开始执行游戏act数据保存: act%v", i)
err = s.Save(ctx, i.(int)) err = s.Save(ctx, i.(int))
} else {
g.Log().Errorf(ctx, "游戏act数据保存超时: act=%v", i)
} }
return true return true
}) })

View File

@@ -56,7 +56,7 @@ func (s *sGameKv) SavesV1() (err error) {
err = tools.Redis.RedisScanV2("user:kv:*", func(keys []string) (err error) { err = tools.Redis.RedisScanV2("user:kv:*", func(keys []string) (err error) {
//判断是否超时 //判断是否超时
if gtime.Now().After(RunTimeMax) { if gtime.Now().After(RunTimeMax) {
g.Log().Debug(ctx, "执行超时了,停止执行!") g.Log().Error(ctx, "执行超时了,停止执行!")
return return
} }

View File

@@ -1,11 +1,15 @@
package utility_go package utility_go
import ( import (
"context"
"time"
"github.com/ayflying/utility_go/config" "github.com/ayflying/utility_go/config"
"github.com/ayflying/utility_go/internal/boot" "github.com/ayflying/utility_go/internal/boot"
_ "github.com/ayflying/utility_go/internal/logic" _ "github.com/ayflying/utility_go/internal/logic"
"github.com/gogf/gf/v2/frame/g" "github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gctx" "github.com/gogf/gf/v2/os/gctx"
"github.com/gogf/gf/v2/os/gtimer"
) )
var ( var (
@@ -14,9 +18,12 @@ var (
) )
func init() { func init() {
var err error
g.Log().Debug(ctx, "utility_go init启动完成") g.Log().Debug(ctx, "utility_go init启动完成")
// 初始化配置 // 初始化配置
var err = boot.Boot() gtimer.SetTimeout(ctx, time.Second*5, func(ctx context.Context) {
err = boot.Boot()
})
if err != nil { if err != nil {
panic(err) panic(err)