123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- 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/message"
- _ "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
- }
- func StartScheduler() {
- htConfig := config.GetConfig(contants.HT).(*config.HTBizConfig)
- if htConfig.EnableTask() {
- task.StartTask()
- }
- }
- func init() {
- AddTasksToScheduler()
- StartScheduler()
- }
|