Пример #1
0
 def _change_state(self, engine, state, result=None, progress=None):
     """Update result and change state."""
     old_state = engine.storage.get_task_state(self.uuid)
     if not states.check_task_transition(old_state, state):
         return False
     if state in SAVE_RESULT_STATES:
         engine.storage.save(self.uuid, result, state)
     else:
         engine.storage.set_task_state(self.uuid, state)
     if progress is not None:
         engine.storage.set_task_progress(self.uuid, progress)
     engine._on_task_state_change(self, state, result=result)
     return True
Пример #2
0
    def _is_ready_for_revert(self, task):
        """Checks if task is ready to be reverted."""

        state = self._storage.get_task_state(task.name)
        if not st.check_task_transition(state, st.REVERTING):
            return False

        task_names = []
        for prev_task in self._graph.successors(task):
            task_names.append(prev_task.name)

        task_states = self._storage.get_tasks_states(task_names)
        return all(state in (st.PENDING, st.REVERTED) for state in six.itervalues(task_states))
Пример #3
0
    def _is_ready_for_execute(self, task):
        """Checks if task is ready to be executed."""

        state = self._storage.get_task_state(task.name)
        if not st.check_task_transition(state, st.RUNNING):
            return False

        task_names = []
        for prev_task in self._graph.predecessors(task):
            task_names.append(prev_task.name)

        task_states = self._storage.get_tasks_states(task_names)
        return all(state == st.SUCCESS for state in six.itervalues(task_states))
Пример #4
0
 def test_invalid_task_states(self):
     invalids = [
         # Not a comprhensive set/listing...
         (states.RUNNING, states.PENDING),
         (states.PENDING, states.REVERTED),
         (states.PENDING, states.SUCCESS),
         (states.PENDING, states.FAILURE),
         (states.RETRYING, states.PENDING),
     ]
     for start_state, end_state in invalids:
         # TODO(harlowja): fix this so that it raises instead of
         # returning false...
         self.assertFalse(
             states.check_task_transition(start_state, end_state))
Пример #5
0
    def _is_ready_for_execute(self, task):
        """Checks if task is ready to be executed."""

        state = self._storage.get_task_state(task.name)
        if not st.check_task_transition(state, st.RUNNING):
            return False

        task_names = []
        for prev_task in self._graph.predecessors(task):
            task_names.append(prev_task.name)

        task_states = self._storage.get_tasks_states(task_names)
        return all(state == st.SUCCESS
                   for state in six.itervalues(task_states))
Пример #6
0
 def test_invalid_task_states(self):
     invalids = [
         # Not a comprhensive set/listing...
         (states.RUNNING, states.PENDING),
         (states.PENDING, states.REVERTED),
         (states.PENDING, states.SUCCESS),
         (states.PENDING, states.FAILURE),
         (states.RETRYING, states.PENDING),
     ]
     for start_state, end_state in invalids:
         # TODO(harlowja): fix this so that it raises instead of
         # returning false...
         self.assertFalse(
             states.check_task_transition(start_state, end_state))
Пример #7
0
    def _is_ready_for_execute(self, task):
        """Checks if task is ready to be executed."""
        state = self.get_state(task)
        intention = self._storage.get_atom_intention(task.name)
        transition = st.check_task_transition(state, st.RUNNING)
        if not transition or intention != st.EXECUTE:
            return False

        task_names = []
        for prev_task in self._execution_graph.predecessors(task):
            task_names.append(prev_task.name)

        task_states = self._storage.get_atoms_states(task_names)
        return all(state == st.SUCCESS and intention == st.EXECUTE
                   for state, intention in six.itervalues(task_states))
Пример #8
0
    def _is_ready_for_revert(self, task):
        """Checks if task is ready to be reverted."""
        state = self.get_state(task)
        intention = self._storage.get_atom_intention(task.name)
        transition = st.check_task_transition(state, st.REVERTING)
        if not transition or intention not in (st.REVERT, st.RETRY):
            return False

        task_names = []
        for prev_task in self._execution_graph.successors(task):
            task_names.append(prev_task.name)

        task_states = self._storage.get_atoms_states(task_names)
        return all(state in (st.PENDING, st.REVERTED)
                   for state, intention in six.itervalues(task_states))
Пример #9
0
    def _is_ready_for_execute(self, task):
        """Checks if task is ready to be executed."""
        state = self.get_state(task)
        intention = self._storage.get_atom_intention(task.name)
        transition = st.check_task_transition(state, st.RUNNING)
        if not transition or intention != st.EXECUTE:
            return False

        task_names = []
        for prev_task in self._graph.predecessors(task):
            task_names.append(prev_task.name)

        task_states = self._storage.get_atoms_states(task_names)
        return all(state == st.SUCCESS and intention == st.EXECUTE
                   for state, intention in six.itervalues(task_states))
Пример #10
0
    def _is_ready_for_revert(self, task):
        """Checks if task is ready to be reverted."""
        state = self.get_state(task)
        intention = self._storage.get_atom_intention(task.name)
        transition = st.check_task_transition(state, st.REVERTING)
        if not transition or intention not in (st.REVERT, st.RETRY):
            return False

        task_names = []
        for prev_task in self._execution_graph.successors(task):
            task_names.append(prev_task.name)

        task_states = self._storage.get_atoms_states(task_names)
        return all(state in (st.PENDING, st.REVERTED)
                   for state, intention in six.itervalues(task_states))
Пример #11
0
    def _change_state(self, task, state, result=None, progress=None):
        old_state = self._storage.get_task_state(task.name)
        if not states.check_task_transition(old_state, state):
            return False
        if state in SAVE_RESULT_STATES:
            self._storage.save(task.name, result, state)
        else:
            self._storage.set_task_state(task.name, state)
        if progress is not None:
            self._storage.set_task_progress(task.name, progress)

        task_uuid = self._storage.get_task_uuid(task.name)
        details = dict(task_name=task.name, task_uuid=task_uuid, result=result)
        self._notifier.notify(state, details)
        if progress is not None:
            task.update_progress(progress)
        return True
Пример #12
0
    def _change_state(self, task, state, result=None, progress=None):
        old_state = self._storage.get_task_state(task.name)
        if not states.check_task_transition(old_state, state):
            return False
        if state in SAVE_RESULT_STATES:
            self._storage.save(task.name, result, state)
        else:
            self._storage.set_task_state(task.name, state)
        if progress is not None:
            self._storage.set_task_progress(task.name, progress)

        task_uuid = self._storage.get_task_uuid(task.name)
        details = dict(task_name=task.name,
                       task_uuid=task_uuid,
                       result=result)
        self._notifier.notify(state, details)
        if progress is not None:
            task.update_progress(progress)
        return True
Пример #13
0
 def test_valid_task_states(self):
     for start_state, end_state in states._ALLOWED_TASK_TRANSITIONS:
         self.assertTrue(states.check_task_transition(start_state,
                                                      end_state))
Пример #14
0
 def test_valid_task_states(self):
     for start_state, end_state in states._ALLOWED_TASK_TRANSITIONS:
         self.assertTrue(
             states.check_task_transition(start_state, end_state))