Merge pull request #2553 from reasonerjt/master

State machine recover from panic and set job state to error
This commit is contained in:
Daniel Jiang 2017-06-17 00:03:10 +08:00 committed by GitHub
commit 4993646ebe

View File

@ -77,6 +77,13 @@ func (sm *SM) EnterState(s string) (string, error) {
// It will search the transit map if the next state is "_continue", and
// will enter error state if there's more than one possible path when next state is "_continue"
func (sm *SM) Start(s string) {
defer func() {
if r := recover(); r != nil {
sm.Logger.Errorf("Panic: %v, entering error state", r)
log.Warningf("Panic when handling job: %v, panic: %v, entering error state", sm.CurrentJob, r)
sm.EnterState(models.JobError)
}
}()
n, err := sm.EnterState(s)
log.Debugf("Job: %v, next state from handler: %s", sm.CurrentJob, n)
for len(n) > 0 && err == nil {