fix new statemachine with ips magfield
+ add on_error, on_restart etc. to states.py + add n_retry argument to mercury change/multichange
This commit is contained in:
@@ -118,12 +118,32 @@ class HasStates:
|
||||
self.setFastPoll(False)
|
||||
self.read_status()
|
||||
|
||||
def on_cleanup(self, sm):
|
||||
if isinstance(sm.cleanup_reason, Exception):
|
||||
return self.on_error(sm)
|
||||
if isinstance(sm.cleanup_reason, Start):
|
||||
return self.on_restart(sm)
|
||||
if isinstance(sm.cleanup_reason, Stop):
|
||||
return self.on_stop(sm)
|
||||
self.log.error('bad cleanup reason %r', sm.cleanup_reason)
|
||||
|
||||
def on_error(self, sm):
|
||||
self.log.error('handle error %r', sm.cleanup_reason)
|
||||
self.final_status(ERROR, repr(sm.cleanup_reason))
|
||||
return None
|
||||
|
||||
def on_restart(self, sm):
|
||||
return None
|
||||
|
||||
def on_stop(self, sm):
|
||||
return None
|
||||
|
||||
def start_machine(self, statefunc, fast_poll=True, **kwds):
|
||||
sm = self._state_machine
|
||||
sm.status = self.get_status(statefunc, BUSY)
|
||||
if sm.statefunc:
|
||||
sm.status = sm.status[0], 'restarting'
|
||||
sm.start(statefunc, **kwds)
|
||||
sm.start(statefunc, cleanup=kwds.pop('cleanup', self.on_cleanup), **kwds)
|
||||
self.read_status()
|
||||
if fast_poll:
|
||||
sm.reset_fast_poll = True
|
||||
|
||||
Reference in New Issue
Block a user