- optimize tasksch channel.

This commit is contained in:
gazebo
2018-10-21 17:09:08 +08:00
parent 0fb6fe27fe
commit c818c45a4d
3 changed files with 12 additions and 17 deletions

View File

@@ -101,8 +101,8 @@ func (t *BaseTask) Init(parallelCount, batchSize int, isContinueWhenError bool,
t.TerminatedAt = utils.DefaultTimeValue
t.TotalItemCount = totalItemCount
t.TotalJobCount = totalJobCount
t.quitChan = make(chan int, 1)
t.finishChan = make(chan int, 1)
t.quitChan = make(chan int)
t.finishChan = make(chan int)
t.Status = TaskStatusWorking
t.C = t.finishChan
@@ -228,11 +228,17 @@ func (t *BaseTask) run(taskHandler func()) {
}()
taskHandler()
select {
case <-t.quitChan:
default:
close(t.quitChan)
}
for _, subTask := range t.Children {
if _, err := subTask.GetResult(0); err != nil {
globals.SugarLogger.Warnf("BaseTask run, failed with error:%v", err)
}
}
close(t.finishChan)
})
}