1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- package task
- import (
- "eta/eta_mini_ht_api/common/component/config"
- "eta/eta_mini_ht_api/common/contants"
- "eta/eta_mini_ht_api/task/base"
- _ "eta/eta_mini_ht_api/task/eta/author"
- _ "eta/eta_mini_ht_api/task/eta/permission"
- _ "eta/eta_mini_ht_api/task/message"
- _ "eta/eta_mini_ht_api/task/order"
- _ "eta/eta_mini_ht_api/task/product"
- _ "eta/eta_mini_ht_api/task/report"
- _ "eta/eta_mini_ht_api/task/sms"
- "github.com/beego/beego/v2/server/web"
- "github.com/beego/beego/v2/task"
- )
- func AddTasksToScheduler() {
- for _, t := range base.GetTasks() {
- if needAddTask(t.RunMode, web.BConfig.RunMode) {
- tk := task.NewTask(string(t.Name), t.Cron, t.Run)
- task.AddTask(string(t.Name), tk)
- }
- }
- }
- func needAddTask(taskRunMode string, runMode string) bool {
- if taskRunMode == base.PROD {
- return true
- }
- if taskRunMode == base.TEST {
- if runMode == base.PROD {
- return false
- }
- return true
- }
- if taskRunMode == base.DEV {
- if runMode == base.DEV {
- return true
- }
- return false
- }
- if taskRunMode == base.FORBIDDEN {
- return false
- }
- return false
- }
- // StartScheduler 启动任务调度器
- func StartScheduler() {
- htConfig := config.GetConfig(contants.HT).(*config.HTBizConfig)
- if htConfig.EnableTask() {
- task.StartTask()
- }
- }
- func init() {
- AddTasksToScheduler()
- StartScheduler()
- }
|