From c5e09f32811c48f695853f480d76fc5944cdbf6a Mon Sep 17 00:00:00 2001 From: meixiongfeng <766881921@qq.com> Date: Tue, 23 May 2023 19:11:50 +0800 Subject: [PATCH] =?UTF-8?q?=E5=95=86=E9=98=9F=E7=BB=93=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/timer/caravanrank.go | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/modules/timer/caravanrank.go b/modules/timer/caravanrank.go index dec8c111d..d7cc2ce1d 100644 --- a/modules/timer/caravanrank.go +++ b/modules/timer/caravanrank.go @@ -2,10 +2,12 @@ package timer import ( "context" + "fmt" "go_dreamfactory/comm" "go_dreamfactory/lego/base" "go_dreamfactory/lego/core" "go_dreamfactory/lego/core/cbase" + "go_dreamfactory/lego/sys/cron" "go_dreamfactory/lego/sys/log" "go_dreamfactory/lego/sys/timewheel" "go_dreamfactory/modules" @@ -68,26 +70,22 @@ func (this *CaravanRank) GetGlobalConf() *cfg.GameGlobalData { func (this *CaravanRank) Start() (err error) { err = this.MCompModel.Start() opentime := this.service.GetOpentime().Unix() - - //cron.AddFunc("30 10 1 * * ?", this.TimerSeason) - //seasonTime := this.GetGlobalConf().BusinessRewardday * 24 * 3600 - if configure.Now().Unix() < opentime { // 开服时间是未来可能存在问题 return } - // subTime := int32(configure.Now().Unix() - opentime) - // if subTime < seasonTime { - // this.cTimerObj = timewheel.Add(time.Second*time.Duration(subTime), this.TimerSeason, nil) - // } else { - // s := configure.Now().Unix() - (configure.Now().Unix()-opentime)%int64(subTime) + int64(seasonTime) - // this.cTimerObj = timewheel.Add(time.Second*time.Duration(s), this.TimerSeason, nil) - // } + //获取时分秒 + currentTime := time.Unix(opentime, 0) + m := currentTime.Minute() + s := currentTime.Second() + day := this.GetGlobalConf().BusinessRewardday + cronStr := fmt.Sprintf("%d %d */%d * * ?", m, s, day) // 每天的 + cron.AddFunc(cronStr, this.TimerSeason) return } -func (this *CaravanRank) TimerSeason(task *timewheel.Task, args ...interface{}) { - this.module.Debugf("==%d", time.Now().Unix()) +func (this *CaravanRank) TimerSeason() { + if _, err := this.service.RpcGo(context.Background(), comm.Service_Worker, string(comm.Rpc_ModuleCaravanSettlement), @@ -96,9 +94,5 @@ func (this *CaravanRank) TimerSeason(task *timewheel.Task, args ...interface{}) ); err != nil { this.module.Errorln(err) } - if this.cTimerObj != nil { - timewheel.Remove(this.cTimerObj) - } // 重新开启一个时间轮 - this.cTimerObj = timewheel.Add(time.Second*time.Duration(this.GetGlobalConf().BusinessRewardday), this.TimerSeason, nil) }