提交 e174fe94 authored 作者: mooncake's avatar mooncake

xcron 使用eventbus方式初始化

上级 c33da749
......@@ -24,6 +24,7 @@ import (
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/app"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/logger"
_ "gitlab.wanzhuangkj.com/tush/xpkg/xcron"
)
func init() {
......
......@@ -24,7 +24,6 @@ import (
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/logger"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/text"
"gitlab.wanzhuangkj.com/tush/xpkg/xcommon/validator"
"gitlab.wanzhuangkj.com/tush/xpkg/xcron"
"gitlab.wanzhuangkj.com/tush/xpkg/xutils/weblogutils"
)
......@@ -142,7 +141,5 @@ func New() *gin.Engine {
global.G.Engine = r
xcron.Init()
return r
}
package xcron
import (
"context"
"github.com/jinzhu/copier"
"gitlab.wanzhuangkj.com/tush/xpkg/config"
"gitlab.wanzhuangkj.com/tush/xpkg/database"
"gitlab.wanzhuangkj.com/tush/xpkg/gin/engine"
"gitlab.wanzhuangkj.com/tush/xpkg/global"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/eventbus"
"gitlab.wanzhuangkj.com/tush/xpkg/xcron/cache"
"gitlab.wanzhuangkj.com/tush/xpkg/xcron/dao"
)
func init() {
eventbus.Eb.Subscribe(eventbus.TopicCronInit, func(ctx context.Context) {
Init()
})
}
func Init() {
initXCron()
initLocalCron()
......@@ -17,9 +26,7 @@ func Init() {
func initLocalCron() {
var cron config.Cron
contextPath := ""
config.Read(func(c *config.Config) {
contextPath = c.App.ContextPath
_ = copier.Copy(&cron, c.Cron)
})
if !cron.Enable {
......@@ -36,6 +43,6 @@ func initLocalCron() {
initCron()
g := global.G.Engine
if g != nil {
engine.RegisterRouters(g, contextPath+"/internal", CronRouterApis)
engine.RegisterRouters(g, "/internal", CronRouterApis)
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论