MCPcopy Create free account
hub / github.com/devfeel/dottask / applyConfig

Method applyConfig

tasks.go:124–165  ·  view source on GitHub ↗

applyConfig apply task config with AppConfig

(config *AppConfig)

Source from the content-addressed store, hash-verified

122
123// applyConfig apply task config with AppConfig
124func (service *TaskService) applyConfig(config *AppConfig) *TaskService {
125 service.Config = config
126 if service.logger == nil {
127 if service.Config.Global.LogPath != "" {
128 service.SetLogger(NewFileLogger(service.Config.Global.LogPath))
129 } else {
130 service.SetLogger(NewFmtLogger())
131 }
132 }
133 for _, v := range service.Config.Tasks {
134 if handler, exists := service.GetHandler(v.HandlerName); exists {
135 if v.TaskType == TaskType_Cron && v.Express != "" {
136 _, err := service.CreateCronTask(v.TaskID, v.IsRun, v.Express, handler, v)
137 if err != nil {
138 service.Logger().Warn("CreateCronTask failed [" + err.Error() + "] [" + fmt.Sprint(v) + "]")
139 } else {
140 service.Logger().Debug("CreateCronTask success [" + fmt.Sprint(v) + "]")
141 }
142 } else if v.TaskType == TaskType_Loop && v.Interval > 0 {
143 _, err := service.CreateLoopTask(v.TaskID, v.IsRun, v.DueTime, v.Interval, handler, v)
144 if err != nil {
145 service.Logger().Warn("CreateLoopTask failed [" + err.Error() + "] [" + fmt.Sprint(v) + "]")
146 } else {
147 service.Logger().Debug("CreateLoopTask success [" + fmt.Sprint(v) + "]")
148 }
149 } else if v.TaskType == TaskType_Queue && v.Interval > 0 {
150 _, err := service.CreateQueueTask(v.TaskID, v.IsRun, v.Interval, handler, v, v.QueueSize)
151 if err != nil {
152 service.Logger().Warn("CreateQueueTask failed [" + err.Error() + "] [" + fmt.Sprint(v) + "]")
153 } else {
154 service.Logger().Debug("CreateQueueTask success [" + fmt.Sprint(v) + "]")
155 }
156 } else {
157 service.Logger().Warn("CreateTask failed not match config [" + fmt.Sprint(v) + "]")
158 }
159
160 } else {
161 service.Logger().Warn("CreateTask failed not exists handler [" + fmt.Sprint(v) + "]")
162 }
163 }
164 return service
165}
166
167// LoadConfigHandler load config handler and init task config
168func (service *TaskService) LoadConfigHandler(configHandler ConfigHandle, configSource string) *TaskService {

Callers 2

LoadFileConfigMethod · 0.95
LoadConfigHandlerMethod · 0.95

Calls 11

SetLoggerMethod · 0.95
GetHandlerMethod · 0.95
CreateCronTaskMethod · 0.95
LoggerMethod · 0.95
CreateLoopTaskMethod · 0.95
CreateQueueTaskMethod · 0.95
NewFileLoggerFunction · 0.85
NewFmtLoggerFunction · 0.85
WarnMethod · 0.65
ErrorMethod · 0.65
DebugMethod · 0.65

Tested by

no test coverage detected