Exemplo n.º 1
0
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)
Exemplo n.º 2
0
def end_project(project_id):
    """
    Mark the specified project and its component tasks as aborted.

    Args:
        project_id (int): The ID of the project to abort.

    Returns:
        None
    """
    project = Project.objects.get(id=project_id)
    project.status = Project.Status.ABORTED
    project.save()
    for task in project.tasks.all():
        task.status = Task.Status.ABORTED
        task.save()
        notify_status_change(task, assignment_history(task))
        notify_project_status_change(project)
    archive_project_slack_group(project)