上传定时模块
This commit is contained in:
parent
2949f8880f
commit
23176056ac
@ -54,6 +54,7 @@ const (
|
||||
ModuleGourmet core.M_Modules = "gourmet" //美食馆
|
||||
ModuleRtask core.M_Modules = "rtask" //随机任务
|
||||
ModuleSmithy core.M_Modules = "smithy" //铁匠铺
|
||||
ModuleTimer core.M_Modules = "timer" //定时任务模块
|
||||
)
|
||||
|
||||
//数据表名定义处
|
||||
|
33
modules/timer/forum.go
Normal file
33
modules/timer/forum.go
Normal file
@ -0,0 +1,33 @@
|
||||
package timer
|
||||
|
||||
import (
|
||||
"go_dreamfactory/modules"
|
||||
|
||||
"go_dreamfactory/lego/core"
|
||||
"go_dreamfactory/lego/sys/cron"
|
||||
)
|
||||
|
||||
/*
|
||||
装备模块 API
|
||||
*/
|
||||
type forumComp struct {
|
||||
modules.MCompGate
|
||||
service core.IService
|
||||
}
|
||||
|
||||
//组件初始化接口
|
||||
func (this *forumComp) Init(service core.IService, module core.IModule, comp core.IModuleComp, options core.IModuleOptions) (err error) {
|
||||
this.MCompGate.Init(service, module, comp, options)
|
||||
this.service = service
|
||||
return
|
||||
}
|
||||
|
||||
func (this *forumComp) Start() (err error) {
|
||||
err = this.MCompGate.Start()
|
||||
cron.AddFunc("*/5 * * * * ?", this.Timer) //每五秒执行一次
|
||||
return
|
||||
}
|
||||
|
||||
func (this *forumComp) Timer() {
|
||||
|
||||
}
|
45
modules/timer/module.go
Normal file
45
modules/timer/module.go
Normal file
@ -0,0 +1,45 @@
|
||||
package timer
|
||||
|
||||
import (
|
||||
"go_dreamfactory/comm"
|
||||
"go_dreamfactory/lego/base"
|
||||
"go_dreamfactory/lego/core"
|
||||
"go_dreamfactory/lego/core/cbase"
|
||||
)
|
||||
|
||||
/*
|
||||
模块名:定时任务
|
||||
描述:处理区服集群下需要做的一些定时任务
|
||||
开发:李伟
|
||||
*/
|
||||
func NewModule() core.IModule {
|
||||
m := new(Timer)
|
||||
return m
|
||||
}
|
||||
|
||||
type Timer struct {
|
||||
cbase.ModuleBase
|
||||
service base.IRPCXService //rpc服务对象 通过这个对象可以发布服务和调用其他服务的接口
|
||||
}
|
||||
|
||||
//模块名
|
||||
func (this *Timer) GetType() core.M_Modules {
|
||||
return comm.ModuleTimer
|
||||
}
|
||||
|
||||
//模块初始化接口 注册用户创建角色事件
|
||||
func (this *Timer) Init(service core.IService, module core.IModule, options core.IModuleOptions) (err error) {
|
||||
err = this.ModuleBase.Init(service, module, options)
|
||||
this.service = service.(base.IRPCXService)
|
||||
return
|
||||
}
|
||||
|
||||
func (this *Timer) Start() (err error) {
|
||||
err = this.ModuleBase.Start()
|
||||
return
|
||||
}
|
||||
|
||||
//装备组件
|
||||
func (this *Timer) OnInstallComp() {
|
||||
this.ModuleBase.OnInstallComp()
|
||||
}
|
@ -4,6 +4,7 @@ import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"go_dreamfactory/modules/mgolog"
|
||||
"go_dreamfactory/modules/timer"
|
||||
"go_dreamfactory/modules/web"
|
||||
"go_dreamfactory/services"
|
||||
"go_dreamfactory/sys/db"
|
||||
@ -11,6 +12,7 @@ import (
|
||||
"go_dreamfactory/lego"
|
||||
"go_dreamfactory/lego/base/rpcx"
|
||||
"go_dreamfactory/lego/core"
|
||||
"go_dreamfactory/lego/sys/cron"
|
||||
"go_dreamfactory/lego/sys/log"
|
||||
)
|
||||
|
||||
@ -35,6 +37,7 @@ func main() {
|
||||
lego.Run(s, //运行模块
|
||||
mgolog.NewModule(),
|
||||
web.NewModule(),
|
||||
timer.NewModule(),
|
||||
)
|
||||
}
|
||||
|
||||
@ -52,6 +55,14 @@ type Service struct {
|
||||
//初始化worker需要的一些系统工具
|
||||
func (this *Service) InitSys() {
|
||||
this.ServiceBase.InitSys()
|
||||
|
||||
//定时系统
|
||||
if err := cron.OnInit(nil); err != nil {
|
||||
panic(fmt.Sprintf("init sys.cron err: %s", err.Error()))
|
||||
} else {
|
||||
log.Infof("init sys.cron success!")
|
||||
}
|
||||
|
||||
//存储系统
|
||||
if err := db.OnInit(this.GetSettings().Sys["db"]); err != nil {
|
||||
panic(fmt.Sprintf("init sys.db err: %s", err.Error()))
|
||||
|
Loading…
Reference in New Issue
Block a user