go_dreamfactory/modules/timer/vikingrank.go

68 lines
1.6 KiB
Go

package timer
import (
"context"
"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/timewheel"
"go_dreamfactory/modules"
"go_dreamfactory/pb"
"go_dreamfactory/sys/configure"
"go_dreamfactory/sys/db"
"go_dreamfactory/utils"
)
type VikingRank struct {
cbase.ModuleBase
modules.MCompModel
service base.IRPCXService
module *Timer
cTimerObj *timewheel.Task
}
//组件初始化接口
func (this *VikingRank) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
this.TableName = comm.TableViking
this.MCompModel.Init(service, module, comp, options)
this.module = module.(*Timer)
this.service = service.(base.IRPCXService)
return
}
func (this *VikingRank) Start() (err error) {
if !db.IsCross() {
return
}
err = this.MCompModel.Start()
opentime := this.service.GetOpentime().Unix()
if configure.Now().Unix() < opentime { // 开服时间是未来可能存在问题
return
}
// 0 0 0 ? * MON // 每周一零点
cron.AddFunc("0 0 0 ? * MON", this.TimerSeason)
//this.TimerSeason() // 删除测试
return
}
func (this *VikingRank) TimerSeason() {
endTime := utils.WeekIntervalTime(configure.Now().Unix())
this.module.Debugf("TimerSeason end: %d,cur time:%d", endTime, configure.Now().Unix())
if err := this.service.RpcCall(
context.Background(),
comm.Service_Worker,
string(comm.Rpc_ModuleVikingFigthEnd),
pb.EmptyReq{},
nil,
); err != nil {
this.module.Errorln(err)
}
}