mirror of https://github.com/shunfei/cronsun
proc: 保证执行中的任务信息一致
parent
fa8a6451ee
commit
a65dab0d43
|
@ -134,7 +134,7 @@ type Process struct {
|
|||
|
||||
running bool
|
||||
hasPut bool
|
||||
timer *time.Timer
|
||||
wg sync.WaitGroup
|
||||
done chan struct{}
|
||||
}
|
||||
|
||||
|
@ -216,17 +216,17 @@ func (p *Process) Start() {
|
|||
return
|
||||
}
|
||||
|
||||
p.timer = time.NewTimer(time.Duration(conf.Config.ProcReq) * time.Second)
|
||||
p.done = make(chan struct{})
|
||||
|
||||
p.wg.Add(1)
|
||||
go func() {
|
||||
select {
|
||||
case <-p.done:
|
||||
case <-p.timer.C:
|
||||
case <-time.After(time.Duration(conf.Config.ProcReq) * time.Second):
|
||||
if err := p.put(); err != nil {
|
||||
log.Warnf("proc put err: %s", err.Error())
|
||||
}
|
||||
}
|
||||
p.wg.Done()
|
||||
}()
|
||||
}
|
||||
|
||||
|
@ -240,10 +240,7 @@ func (p *Process) Stop() error {
|
|||
close(p.done)
|
||||
}
|
||||
|
||||
if p.timer != nil {
|
||||
p.timer.Stop()
|
||||
}
|
||||
|
||||
p.wg.Wait()
|
||||
err := p.del()
|
||||
p.hasPut = false
|
||||
return err
|
||||
|
|
Loading…
Reference in New Issue