Exemplo n.º 1
0
def list(request):
    taskapi = TaskAPI()
    tasktable = []
    for task in CeleryTaskTracker.objects.filter(owner=request.user.username):
        tclass = getattr(tasks, task.taskclass)
        status = tclass.AsyncResult(task.taskid)
        stat_str = status.state
        if status.info:
            stat_str += ": %s" % status.info
        tasktable.append(dict(id=task.taskid,
                              command=task.taskclass,
                              status=stat_str,
                              repo=None,
                              type='sponge'))
    pulp_tasks = taskapi.list()
    if pulp_tasks:
        repos = repo_utils.get_repos()
        for task in taskapi.list():
            if task['start_time'] is not None and task['state'] != 'finished':
                status = task['state']
                command = task['method_name'].lstrip("_")
                if task['exception']:
                    status += ": " + task['exception']
                if task['scheduler'] == 'interval':
                    ttype = task['scheduler']
                    command = "Scheduled %s" % command
                else:
                    ttype = 'pulp'
                repo = None
                for arg in task['args']:
                    if arg in repos:
                        repo = arg
                        break
                tasktable.append(dict(id=task['id'],
                                      command=command,
                                      status=status,
                                      repo=repo,
                                      started=parse_iso8601_datetime(task['start_time']),
                                      type=ttype))
    return dict(tasks=tasktable)