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

xcron 使用eventbus方式初始化

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