优化结构
This commit is contained in:
@@ -120,14 +120,7 @@ func (s *TaskScheduler) Stop(ctx context.Context) error {
|
||||
}
|
||||
// Keep the lifecycle lock while closing subscriber channels so a new SSE
|
||||
// subscription cannot arrive between the shutdown flag and the close.
|
||||
s.subMu.Lock()
|
||||
for userID, subscribers := range s.subscribers {
|
||||
for ch := range subscribers {
|
||||
close(ch)
|
||||
}
|
||||
delete(s.subscribers, userID)
|
||||
}
|
||||
s.subMu.Unlock()
|
||||
s.closeSubscribers()
|
||||
s.runMu.Unlock()
|
||||
s.ctxMu.Lock()
|
||||
cancel := s.cancel
|
||||
@@ -323,7 +316,7 @@ func (s *TaskScheduler) run(ctx context.Context, task *taskbiz.TimedTask, trigge
|
||||
}
|
||||
alertCtx, cancel := context.WithTimeout(context.WithoutCancel(ctx), 3*time.Second)
|
||||
defer cancel()
|
||||
ids, err := s.authorities.AuthorityUserIDs(alertCtx, 888)
|
||||
ids, err := s.authorities.AuthorityUserIDs(alertCtx, system.SuperAdminAuthorityID)
|
||||
if err != nil {
|
||||
logger.Error("query timed task alert recipients failed", "error", err)
|
||||
return
|
||||
@@ -368,10 +361,10 @@ func parseTaskSchedule(task *taskbiz.TimedTask) (cron.Schedule, error) {
|
||||
}
|
||||
|
||||
func cloneTimedTask(task *taskbiz.TimedTask) *taskbiz.TimedTask {
|
||||
copy := *task
|
||||
copy.Params = append([]byte(nil), task.Params...)
|
||||
copy.HTTPHeader = append([]byte(nil), task.HTTPHeader...)
|
||||
return ©
|
||||
clone := *task
|
||||
clone.Params = append([]byte(nil), task.Params...)
|
||||
clone.HTTPHeader = append([]byte(nil), task.HTTPHeader...)
|
||||
return &clone
|
||||
}
|
||||
|
||||
func (s *TaskScheduler) scheduleLocked(task *taskbiz.TimedTask, schedule cron.Schedule) {
|
||||
@@ -472,10 +465,10 @@ func (s *TaskScheduler) Subscribe(userID uint) chan []byte {
|
||||
s.runMu.Unlock()
|
||||
return ch
|
||||
}
|
||||
s.subMu.Lock()
|
||||
if s.subscribers == nil {
|
||||
s.subscribers = make(map[uint]map[chan []byte]struct{})
|
||||
}
|
||||
s.subMu.Lock()
|
||||
if s.subscribers[userID] == nil {
|
||||
s.subscribers[userID] = map[chan []byte]struct{}{}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user