go_dreamfactory/modules/timer/stoneboss.go

49 lines
1.1 KiB
Go

package timer
import (
"context"
"go_dreamfactory/comm"
"go_dreamfactory/modules"
"go_dreamfactory/pb"
"go_dreamfactory/sys/db"
"go_dreamfactory/lego/base"
"go_dreamfactory/lego/core"
"go_dreamfactory/lego/sys/cron"
)
type StoneComp struct {
modules.MCompConfigure
service base.IRPCXService
module *Timer
}
// 组件初始化接口
func (this *StoneComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
this.MCompConfigure.Init(service, module, comp, options)
this.service = service.(base.IRPCXService)
this.module = module.(*Timer)
return
}
func (this *StoneComp) Start() (err error) {
err = this.MCompConfigure.Start()
if !db.IsCross() {
if _, err = cron.AddFunc("5 0 1 ? * 1", this.timer); err != nil { // 每周一1点触发
this.module.Errorf("cron.AddFunc err:%v", err)
}
}
return
}
func (this *StoneComp) timer() {
if _, err := this.service.RpcGo(context.Background(),
comm.Service_Worker,
string(comm.Rpc_ModuleStoneBossSettlement),
pb.EmptyReq{},
nil,
); err != nil {
this.module.Errorln(err)
}
}