diff --git a/pandora/archive/queue.py b/pandora/archive/queue.py index 9f7c0072f..199053d32 100644 --- a/pandora/archive/queue.py +++ b/pandora/archive/queue.py @@ -22,26 +22,23 @@ def parse_job(job): if job['time_start']: start_time = datetime.fromtimestamp(time() - (kombu.five.monotonic() - job['time_start'])) r.update({ - 'started': start_time, - 'running': (datetime.now() - start_time).total_seconds() + 'started': start_time, + 'running': (datetime.now() - start_time).total_seconds() }) if f.encoding: r['status'] = f.encoding_status() return r def status(): - status = { - 'active': [], - 'queued': [], - } + status = [] encoding_jobs = ('archive.tasks.extract_stream', 'archive.tasks.process_stream') c = celery.task.control.inspect() for job in c.active(safe=True).get('celery@pandora-encoding', []): if job['name'] in encoding_jobs: - status['active'].append(parse_job(job)) + status.append(parse_job(job)) for job in c.reserved(safe=True).get('celery@pandora-encoding', []): if job['name'] in encoding_jobs: - status['queued'].append(parse_job(job)) + status.append(parse_job(job)) return status diff --git a/pandora/archive/views.py b/pandora/archive/views.py index 7ba6927d7..012a9d67f 100644 --- a/pandora/archive/views.py +++ b/pandora/archive/views.py @@ -21,9 +21,10 @@ import item.tasks from oxdjango.api import actions from changelog.models import add_changelog -import models -import tasks -from chunk import process_chunk +from . import models +from . import queue +from . import tasks +from .chunk import process_chunk @login_required_json @@ -710,3 +711,9 @@ def getMediaInfo(request, data): return render_to_json_response(response) actions.register(getMediaInfo) + +def getEncodingStatus(request, data): + response = json_response() + response['data']['status'] = queue.status() + return render_to_json_response(response) +actions.register(getEncodingStatus, cache=False)