优化结构

This commit is contained in:
Yvan
2026-08-27 22:33:43 +08:00
parent 5052835fcb
commit e407d3ac10
86 changed files with 3151 additions and 726 deletions
-28
View File
@@ -325,34 +325,6 @@ func (s *TaskScheduler) run(ctx context.Context, task *taskbiz.TimedTask, trigge
}
}
func (s *TaskScheduler) Schedule(task *taskbiz.TimedTask) error {
if task == nil {
return errors.New("定时任务不能为空")
}
var schedule cron.Schedule
var err error
if task.Enabled {
schedule, err = parseTaskSchedule(task)
if err != nil {
return err
}
}
s.mu.Lock()
defer s.mu.Unlock()
s.runMu.Lock()
stopping := s.stopping
s.runMu.Unlock()
if stopping {
return errors.New("任务调度器正在停止")
}
s.removeLocked(task.ID)
if !task.Enabled {
return nil
}
s.scheduleLocked(cloneTimedTask(task), schedule)
return nil
}
func parseTaskSchedule(task *taskbiz.TimedTask) (cron.Schedule, error) {
if task.WithSeconds {
return cron.NewParser(cron.Second | cron.Minute | cron.Hour | cron.Dom | cron.Month | cron.Dow | cron.Descriptor).Parse(task.Spec)