Example #1
0
    def on_run(self, *tasks, subtasks=(), finite=True, **kwargs):
        """
        :param tasks: Tasks to be run concurrently.
        :param subtasks: More tasks to be run concurrently.
        :param finite: If True, each task is considered finished if .has_ever_finished is True. Tasks are not run if
        .has_ever_finished is True (and finite is True).
        """

        subtasks_iterable, subtasks_iterable_copy = itertools.tee(
            itertools.chain(tasks, subtasks))
        all_success = True

        for task in subtasks_iterable:
            if not should_run(task, finite):
                continue
            task()
            all_success = all_success and (not task.finished or task.success)

        if not all_success:
            self.finish(success=False)
            return

        for task in subtasks_iterable_copy:
            if not should_finish(task, finite):
                break
        else:
            self.finish()
Example #2
0
    def on_run(self, *args, finite=True, **kwargs):
        if should_run(self.main_task, finite):
            self.main_task()

        if should_finish(self.main_task, finite):
            if self.main_task.success:
                self.run_branch(self.on_success, finite)

            else:
                self.run_branch(self.on_fail, finite)
Example #3
0
    def on_run(self, *tasks, subtasks=(), finite=True, **kwargs):
        """
        :param tasks: Tasks to be run sequentially.
        :param subtasks: More tasks to be run sequentially. Note: these Tasks are run after the `tasks` argument.
        :param finite: If True, each task is considered finished if .has_ever_finished is True. Tasks are not run if
        .has_ever_finished is True (and finite is True).
        """
        subtasks_iterable = itertools.chain(tasks, subtasks)

        for task in subtasks_iterable:
            if not should_run(task, finite):
                continue
            task()
            if finite and task.has_ever_finished and not task.success:
                self.finish(success=False)
                break
            if not task.finished:
                break
        else:
            self.finish()
Example #4
0
 def run_branch(self, branch, finite):
     if should_run(branch, finite):
         branch()
     if should_finish(branch, finite):
         self.finish(success=branch.success)