def create_subsequent_tasks(project): """ Create tasks for a given project whose dependencies have been completed. Args: project (orchestra.models.Project): The project for which to create tasks. Returns: project (orchestra.models.Project): The modified project object. """ workflow_version = project.workflow_version all_steps = workflow_version.steps.all() # get all completed tasks associated with a given project completed_tasks = Task.objects.filter(status=Task.Status.COMPLETE, project=project) completed_step_slugs = set(completed_tasks.values_list('step__slug', flat=True)) machine_tasks_to_schedule = [] for step in all_steps: if step.slug in completed_step_slugs or Task.objects.filter( project=project, step=step).exists(): continue if _are_desired_steps_completed_on_project( step.creation_depends_on, completed_tasks=completed_tasks): if _check_creation_policy(step, project): # create new task and task_assignment task = Task(step=step, project=project, status=Task.Status.AWAITING_PROCESSING) task.save() # Apply todolist templates to Task for template in task.step.todolist_templates_to_apply.all(): add_todolist_template(template.slug, task.id) _preassign_workers(task, AssignmentPolicyType.ENTRY_LEVEL) if not step.is_human: machine_tasks_to_schedule.append(step) if len(machine_tasks_to_schedule) > 0: connection.on_commit(lambda: schedule_machine_tasks( project, machine_tasks_to_schedule)) incomplete_tasks = (Task.objects.filter(project=project) .exclude(Q(status=Task.Status.COMPLETE) | Q(status=Task.Status.ABORTED))) if incomplete_tasks.count() == 0: if project.status != Project.Status.COMPLETED: set_project_status(project.id, 'Completed') archive_project_slack_group(project)
def create_subsequent_tasks(project): """ Create tasks for a given project whose dependencies have been completed. Args: project (orchestra.models.Project): The project for which to create tasks. Returns: project (orchestra.models.Project): The modified project object. """ workflow_version = project.workflow_version all_steps = workflow_version.steps.all() # get all completed tasks associated with a given project completed_tasks = Task.objects.filter(status=Task.Status.COMPLETE, project=project) completed_step_slugs = set( completed_tasks.values_list('step__slug', flat=True)) for step in all_steps: if step.slug in completed_step_slugs or Task.objects.filter( project=project, step=step).exists(): continue if _are_desired_steps_completed_on_project( step.creation_depends_on, completed_tasks=completed_tasks): # create new task and task_assignment task = Task(step=step, project=project, status=Task.Status.AWAITING_PROCESSING) task.save() _preassign_workers(task) if not step.is_human: machine_step_scheduler_module = import_module( settings.MACHINE_STEP_SCHEDULER[0]) machine_step_scheduler_class = getattr( machine_step_scheduler_module, settings.MACHINE_STEP_SCHEDULER[1]) machine_step_scheduler = machine_step_scheduler_class() machine_step_scheduler.schedule(project.id, step.slug)