@@ -30,23 +30,21 @@ const (
3030
3131// Scheduler is the main class for running the tasks
3232type Scheduler struct {
33- l log.LoggerIface
34- chainsChan chan Chain // channel for passing chains to workers
35- pgengine * pgengine.PgEngine
33+ pgengine * pgengine.PgEngine
34+ l log.LoggerIface
35+ chainsChan chan Chain // channel for passing chains to workers
36+ ichainsChan chan IntervalChain // channel for passing interval chains to workers
3637
3738 exclusiveMutex sync.RWMutex //read-write mutex for running regular and exclusive chains
3839
39- // activeChains holds the map of chain ID with context cancel() function, so we can abort chain by request
40- activeChains map [int ]func ()
40+ activeChains map [int ]func () // map of chain ID with context cancel() function to abort chain by request
4141 activeChainMutex sync.Mutex
4242
43- // map of active chains, updated every minute
44- intervalChains map [int ]IntervalChain
45- // create channel for passing interval chains to workers
46- intervalChainsChan chan IntervalChain
43+ intervalChains map [int ]IntervalChain // map of active chains, updated every minute
4744 intervalChainMutex sync.Mutex
48- shutdown chan struct {} // closed when shutdown is called
49- status RunStatus
45+
46+ shutdown chan struct {} // closed when shutdown is called
47+ status RunStatus
5048}
5149
5250// Max returns the maximum number of two arguments
@@ -60,14 +58,14 @@ func Max(x, y int) int {
6058// New returns a new instance of Scheduler
6159func New (pge * pgengine.PgEngine , logger log.LoggerIface ) * Scheduler {
6260 return & Scheduler {
63- l : logger ,
64- pgengine : pge ,
65- chainsChan : make (chan Chain , Max (minChannelCapacity , pge .Resource .CronWorkers * 2 )),
66- intervalChainsChan : make (chan IntervalChain , Max (minChannelCapacity , pge .Resource .IntervalWorkers * 2 )),
67- activeChains : make (map [int ]func ()), //holds cancel() functions to stop chains
68- intervalChains : make (map [int ]IntervalChain ),
69- shutdown : make (chan struct {}),
70- status : RunningStatus ,
61+ l : logger ,
62+ pgengine : pge ,
63+ chainsChan : make (chan Chain , Max (minChannelCapacity , pge .Resource .CronWorkers * 2 )),
64+ ichainsChan : make (chan IntervalChain , Max (minChannelCapacity , pge .Resource .IntervalWorkers * 2 )),
65+ activeChains : make (map [int ]func ()), //holds cancel() functions to stop chains
66+ intervalChains : make (map [int ]IntervalChain ),
67+ shutdown : make (chan struct {}),
68+ status : RunningStatus ,
7169 }
7270}
7371
@@ -98,7 +96,7 @@ func (sch *Scheduler) Run(ctx context.Context) RunStatus {
9896 for w := 1 ; w <= sch .Config ().Resource .IntervalWorkers ; w ++ {
9997 workerCtx , cancel := context .WithCancel (ctx )
10098 defer cancel ()
101- go sch .intervalChainWorker (workerCtx , sch .intervalChainsChan )
99+ go sch .intervalChainWorker (workerCtx , sch .ichainsChan )
102100 }
103101 ctx = log .WithLogger (ctx , sch .l )
104102
0 commit comments