Exemple #1
0
 def _find_start_commands(self):
     return [
         commands.RunTask(
             self.wf_ex,
             t_s,
             self._get_task_inbound_context(t_s)
         )
         for t_s in self.wf_spec.find_start_tasks()
     ]
Exemple #2
0
    def test_rearrange_commands(self):
        no_wait = commands.RunTask(None, None, None, None)
        fail = commands.FailWorkflow(None, None, None, None)
        succeed = commands.SucceedWorkflow(None, None, None, None)

        wait1 = commands.RunTask(None, None, None, None)
        wait1.wait = True
        wait1.unique_key = 'wait1'

        wait2 = commands.RunTask(None, None, None, None)
        wait2.wait = True
        wait2.unique_key = 'wait2'

        wait3 = commands.RunTask(None, None, None, None)
        wait3.wait = True
        wait3.unique_key = 'wait3'

        # 'set state' command is the first, others must be ignored.
        initial = [fail, no_wait, wait1, wait3, wait2]
        expected = [fail]

        cmds = dispatcher._rearrange_commands(initial)

        self.assertEqual(expected, cmds)

        # 'set state' command is the last, tasks before it must be sorted.
        initial = [no_wait, wait2, wait1, wait3, succeed]
        expected = [no_wait, wait1, wait2, wait3, succeed]

        cmds = dispatcher._rearrange_commands(initial)

        self.assertEqual(expected, cmds)

        # 'set state' command is in the middle, tasks before it must be sorted
        # and the task after it must be ignored.
        initial = [wait3, wait2, no_wait, succeed, wait1]
        expected = [no_wait, wait2, wait3, succeed]

        cmds = dispatcher._rearrange_commands(initial)

        self.assertEqual(expected, cmds)
Exemple #3
0
    def _find_start_commands(self):
        t_specs = []

        for t_s in self.wf_spec.get_tasks():
            if not self._has_inbound_transitions(t_s):
                t_specs.append(t_s)

        return [
            commands.RunTask(self.wf_ex, t_s,
                             self._get_task_inbound_context(t_s))
            for t_s in t_specs
        ]
Exemple #4
0
    def _find_next_commands(self):
        """Finds all tasks with resolved dependencies and return them
         in the form of workflow commands.
        """
        cmds = super(ReverseWorkflowController, self)._find_next_commands()

        task_specs = self._find_task_specs_with_satisfied_dependencies()

        return cmds + [
            commands.RunTask(
                self.wf_ex,
                t_s,
                self._get_task_inbound_context(t_s)
            )
            for t_s in task_specs
        ]
    def _find_next_commands(self, task_ex):
        """Finds all tasks with resolved dependencies.

         This method finds all tasks with resolved dependencies and
         returns them in the form of workflow commands.
        """
        cmds = super(ReverseWorkflowController,
                     self)._find_next_commands(task_ex)

        # TODO(rakhmerov): Adapt reverse workflow to non-locking model.
        # 1. Task search must use task_ex parameter.
        # 2. When a task has more than one dependency it's possible to
        #   get into 'phantom read' phenomena and create multiple instances
        #   of the same task. So 'unique_key' in conjunction with 'wait_flag'
        #   must be used to prevent this.

        task_specs = self._find_task_specs_with_satisfied_dependencies()

        return cmds + [
            commands.RunTask(self.wf_ex, self.wf_spec, t_s,
                             self.get_task_inbound_context(t_s))
            for t_s in task_specs
        ]