How to use the orchestra.models.Task.Status function in orchestra

To help you get started, we’ve selected a few orchestra examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github b12io / orchestra / orchestra / utils / task_lifecycle.py View on Github external
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)
github b12io / orchestra / orchestra / utils / task_lifecycle.py View on Github external
# 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)
github b12io / orchestra / orchestra / views.py View on Github external
def new_task_assignment(request, task_type):
    new_tasks_status = {
        'entry_level': Task.Status.AWAITING_PROCESSING,
        'reviewer': Task.Status.PENDING_REVIEW
    }
    try:
        task_status = new_tasks_status[task_type]
    except KeyError:
        raise BadRequest('No such task type')

    worker = Worker.objects.get(user=request.user)
    try:
        task_assignment = get_new_task_assignment(worker, task_status)
    except WorkerCertificationError:
        raise BadRequest('No worker certificates')
    except NoTaskAvailable:
        raise BadRequest('No task')

    task = task_assignment.task
github b12io / orchestra / orchestra / utils / revert.py View on Github external
latest_iterations = (
        get_iteration_history(task, reverse=True)
        .exclude(id__in=changed_items[RevertChange.DELETED.value]))

    num_iterations = latest_iterations.count()
    if num_iterations == 0:
        return Task.Status.AWAITING_PROCESSING
    elif revert_before:
        # Reverting before the first iteration in an assignment means the task
        # is pending review, since at least one iteration exists
        return Task.Status.PENDING_REVIEW
    else:
        # Revert to a processing iteration state
        if num_iterations == 1:
            return Task.Status.PROCESSING
        else:
            previous_status = latest_iterations[1].status
            if previous_status == Iteration.Status.REQUESTED_REVIEW:
                return Task.Status.REVIEWING
            else:
                return Task.Status.POST_REVIEW_PROCESSING
github b12io / orchestra / orchestra / communication / staffing.py View on Github external
def get_available_requests(worker):
    # We want to show a worker only requests for which there is no
    # winner or for which they have not already replied.
    won_responses = StaffingResponse.objects.filter(is_winner=True)
    worker_provided_responses = StaffingResponse.objects.filter(
        request_inquiry__communication_preference__worker=worker)
    remaining_requests = (
        StaffBotRequest.objects
        .filter(inquiries__communication_preference__worker=worker)
        .exclude(task__status=Task.Status.COMPLETE)
        .exclude(task__status=Task.Status.ABORTED)
        .exclude(inquiries__responses__in=won_responses)
        .exclude(inquiries__responses__in=worker_provided_responses)
        .distinct())
    inquiries = (
        StaffingRequestInquiry.objects
        .filter(request__in=remaining_requests)
        .filter(communication_preference__worker=worker)
        .order_by('request__task__start_datetime'))
    # Because we might send multiple request inquiries to the same
    # worker for the same request (e.g., email and slack), we
    # deduplicate the inquiries so that we will return at most one
    # inquiry's worth of content here.
    request_ids = set()
    contexts = []
    staffbot = StaffBot()
github b12io / orchestra / orchestra / utils / task_lifecycle.py View on Github external
task (orchestra.models.Task):
            The completed and skipped task.

    """
    task = Task.objects.get(id=task_id)
    assignment = current_assignment(task)
    if assignment and assignment.worker:
        if assignment.status != TaskAssignment.Status.PROCESSING:
            return task
        task_data = assignment.in_progress_task_data or {}
        task_data.update(_orchestra_internal={'complete_and_skip_task': True})
        submit_task(
            task_id, task_data,
            Iteration.Status.REQUESTED_REVIEW, assignment.worker)
    else:
        task.status = Task.Status.COMPLETE
        task.save()
        for assignment in task.assignments.all():
            assignment.status = TaskAssignment.Status.SUBMITTED
            assignment.save()
    return task
github b12io / orchestra / orchestra / utils / revert.py View on Github external
if num_iterations == 0:
        return Task.Status.AWAITING_PROCESSING
    elif revert_before:
        # Reverting before the first iteration in an assignment means the task
        # is pending review, since at least one iteration exists
        return Task.Status.PENDING_REVIEW
    else:
        # Revert to a processing iteration state
        if num_iterations == 1:
            return Task.Status.PROCESSING
        else:
            previous_status = latest_iterations[1].status
            if previous_status == Iteration.Status.REQUESTED_REVIEW:
                return Task.Status.REVIEWING
            else:
                return Task.Status.POST_REVIEW_PROCESSING
github b12io / orchestra / orchestra / machine_tasks.py View on Github external
project_data = project.project_data
        project_data['project_id'] = project_id
        task_data = function(project_data, prerequisites, **kwargs)
    except Exception:
        task_assignment.status = TaskAssignment.Status.FAILED
        logger.exception('Machine task has failed')
        task_assignment.save()
        return
    task_assignment.status = TaskAssignment.Status.SUBMITTED
    task_assignment.in_progress_task_data = task_data
    task_assignment.save()

    if task.project.status == Project.Status.ABORTED:
        # If a long-running task's project was aborted while running, we ensure
        # the aborted state on the task.
        task.status = Task.Status.ABORTED
        task.save()
    else:
        task.status = Task.Status.COMPLETE
        task.save()

        iteration = get_latest_iteration(task_assignment)
        iteration.status = Iteration.Status.REQUESTED_REVIEW
        iteration.submitted_data = task_data
        iteration.end_datetime = timezone.now()
        iteration.save()

        create_subsequent_tasks(project)
github b12io / orchestra / orchestra / utils / notifications.py View on Github external
def notify_status_change(task, previous_status=None):
    """
    Notify workers after task has changed state
    """
    task_assignments = assignment_history(task)
    current_task_assignment = current_assignment(task)
    current_worker = None
    if current_task_assignment:
        current_worker = current_task_assignment.worker
    message_info = None

    # Notify worker when task initially picked up
    if task.status == Task.Status.PROCESSING:
        message_info = {
            'subject': "You've been assigned to a new task!",
            'message': ("You've been assigned to a new task. We can't wait "
                        "to see the great things you'll do!"),
            'recipient_list': [current_worker.user.email]
        }
    # Notify worker when assignment selected for review
    elif task.status == Task.Status.PENDING_REVIEW:
        message_info = {
            'subject': 'Your task is under review!',
            'message': ('Thanks for all your hard work, {}! The following '
                        'task was randomly selected for review by another '
                        'expert; you should hear back soon!').format(
                            current_worker.user.username),
            'recipient_list': [current_worker.user.email]
        }
github b12io / orchestra / orchestra / utils / revert.py View on Github external
num_iterations = latest_iterations.count()
    if num_iterations == 0:
        return Task.Status.AWAITING_PROCESSING
    elif revert_before:
        # Reverting before the first iteration in an assignment means the task
        # is pending review, since at least one iteration exists
        return Task.Status.PENDING_REVIEW
    else:
        # Revert to a processing iteration state
        if num_iterations == 1:
            return Task.Status.PROCESSING
        else:
            previous_status = latest_iterations[1].status
            if previous_status == Iteration.Status.REQUESTED_REVIEW:
                return Task.Status.REVIEWING
            else:
                return Task.Status.POST_REVIEW_PROCESSING