Skip to content
Snippets Groups Projects
Commit 328f479b authored by Erik Reid's avatar Erik Reid
Browse files

make the response more useful for a ui

parent b898e701
No related branches found
No related tags found
No related merge requests found
import json
import logging
from distutils.util import strtobool
......@@ -75,5 +76,54 @@ def check_update_status():
@routes.route("log", methods=['GET', 'POST'])
@common.require_accepts_json
def load_task_log():
tasks = monitor.load_task_log(current_app.config['INVENTORY_PROVIDER_CONFIG'])
return jsonify(tasks)
FINALIZATION_EVENTS = {'task-succeeded', 'task-failed', 'task-revoked'}
config = current_app.config['INVENTORY_PROVIDER_CONFIG']
r = get_current_redis(config)
cache_key = 'joblog:cached-response'
result = r.get(cache_key)
if result:
result = json.loads(result.decode('utf-8'))
else:
result = {
'pending': [],
'warnings': [],
'errors': [],
'failed': []
}
for task in monitor.load_task_log(current_app.config['INVENTORY_PROVIDER_CONFIG']).values():
for event in task.get('task-warning', []):
result['warnings'].append(event['message'])
for event in task.get('task-error', []):
result['errors'].append(event['message'])
# build the description if task-received is available
description = None
if 'task-received' in task:
event = task['task-received'][0]
description = f'{event["name"]}{event["args"]}'
description += f':{event["uuid"]}'
if 'task-failed' in task:
if not description:
logger.error('found task-failed event without'
f'task-received: {task}')
description = task['task-failed'][0]['uuid']
result['failed'].append(description)
if 'task-started' in task:
finished = set(task.keys()) & FINALIZATION_EVENTS
if not finished:
if not description:
logger.error('found task-started event without'
f'task-received: {task}')
description = task['task-started'][0]['uuid']
result['pending'].append(description)
if not result['pending']:
r.set(cache_key, json.dumps(result))
return jsonify(result)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment