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 running bool
hasPut bool hasPut bool
timer *time.Timer wg sync.WaitGroup
done chan struct{} done chan struct{}
} }
@ -216,17 +216,17 @@ func (p *Process) Start() {
return return
} }
p.timer = time.NewTimer(time.Duration(conf.Config.ProcReq) * time.Second)
p.done = make(chan struct{}) p.done = make(chan struct{})
p.wg.Add(1)
go func() { go func() {
select { select {
case <-p.done: case <-p.done:
case <-p.timer.C: case <-time.After(time.Duration(conf.Config.ProcReq) * time.Second):
if err := p.put(); err != nil { if err := p.put(); err != nil {
log.Warnf("proc put err: %s", err.Error()) log.Warnf("proc put err: %s", err.Error())
} }
} }
p.wg.Done()
}() }()
} }
@ -240,10 +240,7 @@ func (p *Process) Stop() error {
close(p.done) close(p.done)
} }
if p.timer != nil { p.wg.Wait()
p.timer.Stop()
}
err := p.del() err := p.del()
p.hasPut = false p.hasPut = false
return err return err