diff --git a/modules/timer/caravanrank.go b/modules/timer/caravanrank.go index cc94b6a29..965d2ddf0 100644 --- a/modules/timer/caravanrank.go +++ b/modules/timer/caravanrank.go @@ -19,8 +19,9 @@ import ( type CaravanRank struct { cbase.ModuleBase modules.MCompModel - service base.IRPCXService - module *Timer + service base.IRPCXService + module *Timer + cTimerObj *timewheel.Task } const ( @@ -77,10 +78,10 @@ func (this *CaravanRank) Start() (err error) { } subTime := int32(configure.Now().Unix() - opentime) if subTime < seasonTime { - timewheel.Add(time.Second*time.Duration(subTime), this.TimerSeason, nil) + 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) - timewheel.Add(time.Second*time.Duration(s), this.TimerSeason, nil) + this.cTimerObj = timewheel.Add(time.Second*time.Duration(s), this.TimerSeason, nil) } return @@ -96,24 +97,9 @@ 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) - // if _data, err := this.DB.Find(comm.TableUser, bson.M{"merchantmoney": bson.M{"$gt": 0}}); err == nil { - // for _data.Next(context.TODO()) { - - // temp := &pb.DBUser{} - // if err = _data.Decode(temp); err == nil { - - // } - // } - // } - - // sTime := time.Now() - // Query := bson.M{} - // Query["merchantmoney"] = 0 - // _, err := this.DB.UpdateMany(core.SqlTable(comm.TableUser), bson.M{}, bson.M{"$set": Query}, options.MergeUpdateOptions().SetUpsert(true)) //, new(options.UpdateOptions).SetUpsert(true) - // if err != nil { - // this.module.Errorf("UpdateMany error: %v", err) - // } - - // this.module.Debugf("sub time:%d", time.Now().Local().Sub(sTime).Milliseconds()) }