expose encoding status via api

This commit is contained in:
j 2016-05-05 10:49:34 +02:00
parent be163826ef
commit 41cc8e3573
2 changed files with 15 additions and 11 deletions

View file

@ -30,18 +30,15 @@ def parse_job(job):
return r return r
def status(): def status():
status = { status = []
'active': [],
'queued': [],
}
encoding_jobs = ('archive.tasks.extract_stream', 'archive.tasks.process_stream') encoding_jobs = ('archive.tasks.extract_stream', 'archive.tasks.process_stream')
c = celery.task.control.inspect() c = celery.task.control.inspect()
for job in c.active(safe=True).get('celery@pandora-encoding', []): for job in c.active(safe=True).get('celery@pandora-encoding', []):
if job['name'] in encoding_jobs: 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', []): for job in c.reserved(safe=True).get('celery@pandora-encoding', []):
if job['name'] in encoding_jobs: if job['name'] in encoding_jobs:
status['queued'].append(parse_job(job)) status.append(parse_job(job))
return status return status

View file

@ -21,9 +21,10 @@ import item.tasks
from oxdjango.api import actions from oxdjango.api import actions
from changelog.models import add_changelog from changelog.models import add_changelog
import models from . import models
import tasks from . import queue
from chunk import process_chunk from . import tasks
from .chunk import process_chunk
@login_required_json @login_required_json
@ -710,3 +711,9 @@ def getMediaInfo(request, data):
return render_to_json_response(response) return render_to_json_response(response)
actions.register(getMediaInfo) 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)