예제 #1
0
 def create_for_task(cls, celecry_task: Task, a_id, task_name=''):
     """创建关联任务并设置初始进度"""
     task_name = task_name or getattr(celecry_task.request, 'task')
     a_task_result = AssociatedTaskResult.create(a_type_name=task_name,
                                                 a_id=a_id)
     a_task_result.add_task_result(celecry_task.request.id)
     celecry_task.update_state(state=states.PROGRESS, request=celecry_task.request)
예제 #2
0
def update_progress(task: Task, new_status: int):
    """ Set the current progress for the task object (celery)

    Args:
        task (Task):
        new_status (int): The progress bar
    Returns:

    """
    if new_status < 0 or new_status > 100:
        raise ValueError("new_status must be in range [0, 100]")

    try:
        pending_task = PendingTask.objects.get(task_id=task.request.id)
        pending_task.progress = new_status
        pending_task.save()
    except ObjectDoesNotExist:
        pass

    task.update_state(state='PROGRESS',
                      meta={
                          'current': new_status,
                          'total': 100,
                      })