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

@ -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

View file

@ -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)