84 lines
2.0 KiB
Go
84 lines
2.0 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 CaravanRank struct {
|
|
cbase.ModuleBase
|
|
modules.MCompModel
|
|
service base.IRPCXService
|
|
module *Timer
|
|
cTimerObj *timewheel.Task
|
|
}
|
|
|
|
//组件初始化接口
|
|
func (this *CaravanRank) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
|
|
|
this.TableName = comm.TableCaravan
|
|
this.MCompModel.Init(service, module, comp, options)
|
|
this.module = module.(*Timer)
|
|
this.service = service.(base.IRPCXService)
|
|
|
|
return
|
|
}
|
|
func (this *CaravanRank) LoadConfigure(name string, fn interface{}) (err error) {
|
|
return configure.RegisterConfigure(name, fn, nil)
|
|
}
|
|
|
|
//读取配置数据
|
|
func (this *CaravanRank) GetConfigure(name string) (v interface{}, err error) {
|
|
return configure.GetConfigure(name)
|
|
}
|
|
|
|
func (this *CaravanRank) 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)
|
|
|
|
return
|
|
}
|
|
|
|
func (this *CaravanRank) 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_ModuleCaravanSettlement),
|
|
pb.EmptyReq{},
|
|
nil,
|
|
); err != nil {
|
|
this.module.Errorln(err)
|
|
}
|
|
if err := this.service.RpcCall(
|
|
context.Background(),
|
|
comm.Service_Worker,
|
|
string(comm.Rpc_ModuleXXlSettlement),
|
|
pb.EmptyReq{},
|
|
nil,
|
|
); err != nil {
|
|
this.module.Errorln(err)
|
|
}
|
|
}
|