proc: 保证执行中的任务信息一致

pull/1/head
miraclesu 2017-03-22 09:30:47 +08:00
parent fa8a6451ee
commit a65dab0d43
1 changed files with 5 additions and 8 deletions

View File

@ -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