Compare commits

...

2 Commits

Author SHA1 Message Date
ayflying
4c24c4274c 定时器只允许启动一次 2025-03-31 14:57:04 +08:00
ayflying
2a34ce6043 更新g.redis方法的传参 2025-03-27 11:53:19 +08:00
2 changed files with 10 additions and 2 deletions

View File

@@ -231,7 +231,7 @@ func (s *sGameAct) Del(uid int64, actId int) {
keyCache := fmt.Sprintf("act:%v:%v", actId, uid)
//删除活动缓存
g.Redis("redis").Del(ctx, keyCache)
g.Redis().Del(ctx, keyCache)
//删除当前活动储存
g.Model(Name).Where(do.GameAct{

View File

@@ -7,6 +7,7 @@ import (
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gcron"
"github.com/gogf/gf/v2/os/gctx"
"github.com/gogf/gf/v2/os/gtime"
"github.com/gogf/gf/v2/os/gtimer"
"sync"
"time"
@@ -14,6 +15,7 @@ import (
var (
ctx = gctx.New()
startTime *gtime.Time
)
// sSystemCron 结构体定义了系统定时任务的秒计时器。
@@ -110,6 +112,12 @@ func (s *sSystemCron) AddCron(typ v1.CronType, _func func() error) {
// @receiver s
// @return err
func (s *sSystemCron) StartCron() (err error) {
//预防重复启动
if startTime != nil {
return
}
startTime = gtime.Now()
g.Log().Debug(ctx, "启动计划任务定时器详情")
//每秒任务
gtimer.SetInterval(ctx, time.Second, func(ctx context.Context) {