go_dreamfactory/modules/timer/sociaty.go
2023-07-19 17:44:35 +08:00

55 lines
1.2 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 SociatyComp struct {
modules.MCompConfigure
service base.IRPCXService
module *Timer
takes []cron.EntryID
}
// 组件初始化接口
func (this *SociatyComp) 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)
this.takes = make([]cron.EntryID, 0)
return
}
// 自由跨服环境下开启此功能
func (this *SociatyComp) Start() (err error) {
err = this.MCompConfigure.Start()
if db.IsCross() {
if _, err = cron.AddFunc("0 0 1 ? * 1", this.timer); err != nil {
this.module.Errorf("cron.AddFunc err:%v", err)
}
}
return
}
func (this *SociatyComp) timer() {
if _, err := this.service.RpcGo(context.Background(),
comm.Service_Worker,
string(comm.Rpc_ModuleGuildBossSettlement),
pb.EmptyReq{},
nil,
); err != nil {
this.module.Errorln(err)
}
}