diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..723ef36 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea \ No newline at end of file diff --git a/scheduler.go b/scheduler.go index 7b977a7..56b3f75 100644 --- a/scheduler.go +++ b/scheduler.go @@ -55,9 +55,10 @@ func New() *CronSchduler { } type CronSchduler struct { - tasks map[string]*JobModel - ctx context.Context - cancel context.CancelFunc + running bool + tasks map[string]*JobModel + ctx context.Context + cancel context.CancelFunc wg *sync.WaitGroup once *sync.Once @@ -104,7 +105,7 @@ func (c *CronSchduler) reset(srv string, model *JobModel, denyReplace, autoStart } c.tasks[srv] = model - if autoStart { + if autoStart && c.running { c.wg.Add(1) go c.tasks[srv].runLoop(c.wg) } @@ -223,6 +224,7 @@ func (c *CronSchduler) Start() { job.runLoop(c.wg) } + c.running = true }) }