mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-12 02:06:37 +08:00
refactor(core): decouple gin from pkg/util and reduce code duplication
This commit is contained in:
@@ -111,21 +111,7 @@ func ReloadScheduler() error {
|
||||
// 4. 遍历并注册任务
|
||||
taskSvc := getTaskService()
|
||||
for _, s := range schedules {
|
||||
taskName := s.TaskType
|
||||
maxRetry := 3
|
||||
queue := "default"
|
||||
|
||||
if taskSvc != nil {
|
||||
if meta, ok := taskSvc.GetTaskMeta(s.TaskType); ok {
|
||||
taskName = meta.Name
|
||||
if meta.MaxRetry > 0 {
|
||||
maxRetry = meta.MaxRetry
|
||||
}
|
||||
if meta.Queue != "" {
|
||||
queue = meta.Queue
|
||||
}
|
||||
}
|
||||
}
|
||||
taskName, maxRetry, queue := resolveTaskScheduleMeta(taskSvc, s.TaskType)
|
||||
|
||||
// 构造 Asynq 载荷
|
||||
t := asynq.NewTask(taskName, []byte(s.Payload))
|
||||
@@ -160,3 +146,24 @@ func waitForStop(done, signals <-chan struct{}) bool {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
func resolveTaskScheduleMeta(taskSvc contracts.TaskService, taskType string) (name string, maxRetry int, queue string) {
|
||||
name = taskType
|
||||
maxRetry = 3
|
||||
queue = "default"
|
||||
if taskSvc == nil {
|
||||
return
|
||||
}
|
||||
meta, ok := taskSvc.GetTaskMeta(taskType)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
name = meta.Name
|
||||
if meta.MaxRetry > 0 {
|
||||
maxRetry = meta.MaxRetry
|
||||
}
|
||||
if meta.Queue != "" {
|
||||
queue = meta.Queue
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user