Beispiel #1
0
def _revert_task_status(task):
    """
    Reverts the status of an otherwise-reverted task.

    Args:
        task (orchestra.models.Task):
            The task with status to revert.

    Returns:
        task (orchestra.models.Task):
            The task with reverted status.
    """
    assignments = assignment_history(task)
    num_assignments = assignments.count()

    reverted_status = None
    current_assignment_counter = None
    previous_assignment_counter = None
    if num_assignments == 0:
        # No assignment is present
        reverted_status = Task.Status.AWAITING_PROCESSING
    else:
        assignment = last_snapshotted_assignment(task.id)
        if not assignment:
            # Task has an assignment but no snapshots
            reverted_status = Task.Status.PROCESSING
            current_assignment_counter = 0
        else:
            latest_counter = assignment.assignment_counter
            snapshot = assignment.snapshots['snapshots'][-1]
            if snapshot['type'] == TaskAssignment.SnapshotType.REJECT:
                # Task was last rejected back to previous worker
                reverted_status = Task.Status.POST_REVIEW_PROCESSING
                current_assignment_counter = latest_counter - 1
                previous_assignment_counter = latest_counter

            elif (snapshot['type'] in (TaskAssignment.SnapshotType.SUBMIT,
                                       TaskAssignment.SnapshotType.ACCEPT)):
                if latest_counter == num_assignments - 1:
                    # Task was last submitted and no higher-level
                    # assignments are present (reverted tasks will never end
                    # in a completed state)
                    reverted_status = Task.Status.PENDING_REVIEW
                else:
                    reverted_status = Task.Status.REVIEWING
                    previous_assignment_counter = latest_counter
                    current_assignment_counter = latest_counter + 1

    if current_assignment_counter is not None:
        current_assignment = task.assignments.get(
            assignment_counter=current_assignment_counter)
        current_assignment.status = TaskAssignment.Status.PROCESSING
        current_assignment.save()

    if previous_assignment_counter is not None:
        previous_assignment = task.assignments.get(
            assignment_counter=previous_assignment_counter)
        previous_assignment.status = TaskAssignment.Status.SUBMITTED
        previous_assignment.save()

    # TODO(jrbotros): The revert methos should "peel off" snapshots,
    # rather than deleting them in bulk and recalculating the assignment
    # and task statuses; this logic needs to be cleaned up.
    for assignment in task.assignments.all():
        if assignment.status == TaskAssignment.Status.SUBMITTED:
            latest_snapshot = assignment.snapshots['snapshots'][-1]
            assignment.in_progress_task_data = latest_snapshot['data']
            assignment.save()

    task.status = reverted_status
    task.save()
    return task
Beispiel #2
0
def _revert_task_status(task):
    """
    Reverts the status of an otherwise-reverted task.

    Args:
        task (orchestra.models.Task):
            The task with status to revert.

    Returns:
        task (orchestra.models.Task):
            The task with reverted status.
    """
    assignments = assignment_history(task)
    num_assignments = assignments.count()

    reverted_status = None
    current_assignment_counter = None
    previous_assignment_counter = None
    if num_assignments == 0:
        # No assignment is present
        reverted_status = Task.Status.AWAITING_PROCESSING
    else:
        assignment = last_snapshotted_assignment(task.id)
        if not assignment:
            # Task has an assignment but no snapshots
            reverted_status = Task.Status.PROCESSING
            current_assignment_counter = 0
        else:
            latest_counter = assignment.assignment_counter
            snapshot = assignment.snapshots['snapshots'][-1]
            if snapshot['type'] == TaskAssignment.SnapshotType.REJECT:
                # Task was last rejected back to previous worker
                reverted_status = Task.Status.POST_REVIEW_PROCESSING
                current_assignment_counter = latest_counter - 1
                previous_assignment_counter = latest_counter

            elif (snapshot['type'] in (TaskAssignment.SnapshotType.SUBMIT,
                                       TaskAssignment.SnapshotType.ACCEPT)):
                if latest_counter == num_assignments - 1:
                    # Task was last submitted and no higher-level
                    # assignments are present (reverted tasks will never end
                    # in a completed state)
                    reverted_status = Task.Status.PENDING_REVIEW
                else:
                    reverted_status = Task.Status.REVIEWING
                    previous_assignment_counter = latest_counter
                    current_assignment_counter = latest_counter + 1

    if current_assignment_counter is not None:
        current_assignment = task.assignments.get(
            assignment_counter=current_assignment_counter)
        current_assignment.status = TaskAssignment.Status.PROCESSING
        current_assignment.save()

    if previous_assignment_counter is not None:
        previous_assignment = task.assignments.get(
            assignment_counter=previous_assignment_counter)
        previous_assignment.status = TaskAssignment.Status.SUBMITTED
        previous_assignment.save()

    # TODO(jrbotros): The revert methos should "peel off" snapshots,
    # rather than deleting them in bulk and recalculating the assignment
    # and task statuses; this logic needs to be cleaned up.
    for assignment in task.assignments.all():
        if assignment.status == TaskAssignment.Status.SUBMITTED:
            latest_snapshot = assignment.snapshots['snapshots'][-1]
            assignment.in_progress_task_data = latest_snapshot['data']
            assignment.save()

    task.status = reverted_status
    task.save()
    return task
def project_management_information(project_id):
    project = Project.objects.get(id=project_id)
    df = work_time_df([project], human_only=False, complete_tasks_only=False)
    project_information = get_project_information(project.id)
    project_information['project']['status'] = dict(
        Project.STATUS_CHOICES).get(project.status, None)
    project_information['project']['admin_url'] = urljoin(
        settings.ORCHESTRA_URL,
        urlresolvers.reverse('admin:orchestra_project_change',
                             args=(project_id, )))

    for slug, task in project_information['tasks'].items():
        task['admin_url'] = urljoin(
            settings.ORCHESTRA_URL,
            urlresolvers.reverse('admin:orchestra_task_change',
                                 args=(task['id'], )))

        for assignment in task['assignments']:
            assignment['admin_url'] = urljoin(
                settings.ORCHESTRA_URL,
                urlresolvers.reverse('admin:orchestra_taskassignment_change',
                                     args=(assignment['id'], )))

            iterations = df[(df.worker == assignment['worker']['username'])
                            & (df.task_id == task['id'])]
            iterations = iterations[['start_datetime', 'end_datetime']]
            assignment['iterations'] = []
            for idx, info in iterations.T.items():
                iteration = info.to_dict()
                assignment['iterations'].append(iteration)
            if assignment['status'] == 'Processing':
                last_iteration_end = assignment['start_datetime']
                last_assignment = last_snapshotted_assignment(task['id'])
                if last_assignment and len(assignment['iterations']) > 1:
                    last_iteration_end = (
                        last_assignment.snapshots['snapshots'][-1]['datetime'])

                assignment['iterations'].append({
                    'start_datetime': last_iteration_end,
                    'end_datetime': timezone.now()
                })

        if task['status'] in ('Awaiting Processing', 'Pending Review'):
            last_assignment_end = task['start_datetime']
            last_assignment = last_snapshotted_assignment(task['id'])
            if last_assignment:
                last_assignment_end = (
                    last_assignment.snapshots['snapshots'][-1]['datetime'])
            task['assignments'].append({
                'iterations': [{
                    'start_datetime': last_assignment_end,
                    'end_datetime': timezone.now()
                }],
                'snapshots':
                empty_snapshots(),
                'start_datetime':
                last_assignment_end,
                'status':
                'Processing',
                'task':
                task['id'],
                'worker': {
                    'id': None,
                    'username': None
                },
            })
    return project_information