def change_flow_state(self, state): """Transition flow from old state to new state. Returns ``(True, old_state)`` if transition was performed, or ``(False, old_state)`` if it was ignored, or raises a :py:class:`~taskflow.exceptions.InvalidState` exception if transition is invalid. """ old_state = self.get_flow_state() if not states.check_flow_transition(old_state, state): return (False, old_state) self.set_flow_state(state) return (True, old_state)
def _change_state(self, state): with self._state_lock: old_state = self.storage.get_flow_state() if not states.check_flow_transition(old_state, state): return self.storage.set_flow_state(state) details = { 'engine': self, 'flow_name': self.storage.flow_name, 'flow_uuid': self.storage.flow_uuid, 'old_state': old_state, } self.notifier.notify(state, details)
def _change_state(self, state): old_state = self.storage.get_flow_state() if not states.check_flow_transition(old_state, state): return self.storage.set_flow_state(state) try: flow_uuid = self._flow.uuid except AttributeError: # NOTE(harlowja): if the flow was just a single task, then it will # not itself have a uuid, but the constructed flow_detail will. if self._flow_detail is not None: flow_uuid = self._flow_detail.uuid else: flow_uuid = None details = dict(engine=self, flow_name=self._flow.name, flow_uuid=flow_uuid, old_state=old_state) self.notifier.notify(state, details)
def test_bad_transition_raises(self): with self.assertRaisesRegexp(exc.InvalidStateException, '^Flow transition.*not allowed'): states.check_flow_transition(states.FAILURE, states.SUCCESS)
def test_ignored_flow_states(self): for start_state, end_state in states._IGNORED_FLOW_TRANSITIONS: self.assertFalse( states.check_flow_transition(start_state, end_state))
def test_no_resuming_from_pending(self): self.assertFalse( states.check_flow_transition(states.PENDING, states.RESUMING))
def test_resuming_from_running(self): self.assertTrue( states.check_flow_transition(states.RUNNING, states.RESUMING))
def test_same_state(self): self.assertFalse( states.check_flow_transition(states.SUCCESS, states.SUCCESS))
def test_rerunning_allowed(self): self.assertTrue( states.check_flow_transition(states.SUCCESS, states.RUNNING))
def test_valid_flow_states(self): for start_state, end_state in states._ALLOWED_FLOW_TRANSITIONS: self.assertTrue( states.check_flow_transition(start_state, end_state))
def test_valid_flow_states(self): for start_state, end_state in states._ALLOWED_FLOW_TRANSITIONS: self.assertTrue(states.check_flow_transition(start_state, end_state))
def test_ignored_flow_states(self): for start_state, end_state in states._IGNORED_FLOW_TRANSITIONS: self.assertFalse(states.check_flow_transition(start_state, end_state))