feat: 添加过载保护、背压和熔断机制
This commit is contained in:
@@ -14,15 +14,15 @@ import (
|
||||
|
||||
// Scheduler manages task queuing and execution with priority-based scheduling.
|
||||
type Scheduler struct {
|
||||
mu sync.Mutex
|
||||
queue *priorityQueue
|
||||
running map[string]*task.Task
|
||||
maxRunning int
|
||||
maxQueued int
|
||||
notifyCh chan struct{}
|
||||
logger *observability.Logger
|
||||
ctx context.Context
|
||||
cancel context.CancelFunc
|
||||
mu sync.Mutex
|
||||
queue *priorityQueue
|
||||
running map[string]*task.Task
|
||||
maxRunning int
|
||||
maxQueued int
|
||||
notifyCh chan struct{}
|
||||
logger *observability.Logger
|
||||
ctx context.Context
|
||||
cancel context.CancelFunc
|
||||
}
|
||||
|
||||
// NewScheduler creates a new scheduler.
|
||||
@@ -114,6 +114,22 @@ func (s *Scheduler) RunningCount() int {
|
||||
return len(s.running)
|
||||
}
|
||||
|
||||
// GetTask returns a running task by ID, or a queued task by ID.
|
||||
func (s *Scheduler) GetTask(taskID string) (*task.Task, bool) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
if t, ok := s.running[taskID]; ok {
|
||||
return t, true
|
||||
}
|
||||
for i := 0; i < s.queue.Len(); i++ {
|
||||
t := (*s.queue)[i]
|
||||
if t.ID == taskID {
|
||||
return t, true
|
||||
}
|
||||
}
|
||||
return nil, false
|
||||
}
|
||||
|
||||
// Stop shuts down the scheduler.
|
||||
func (s *Scheduler) Stop() {
|
||||
s.cancel()
|
||||
|
||||
Reference in New Issue
Block a user