State machine recover from panic and set job state to error

This commit is contained in:
Tan Jiang 2017-06-16 19:08:59 +08:00
parent 482f91d91a
commit 7a57cb4c87

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 {