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

temporary version of /jobs/log

parent e879940f
Branches
Tags my_prenew_tomas mytomas
No related merge requests found
import json
import logging
from distutils.util import strtobool from distutils.util import strtobool
import jsonschema
from flask import Blueprint, current_app, jsonify, Response, request from flask import Blueprint, current_app, jsonify, Response, request
from inventory_provider.tasks import worker from inventory_provider.tasks import worker
from inventory_provider.routes import common from inventory_provider.routes import common
from inventory_provider.tasks.common import get_current_redis, get_latch from inventory_provider.tasks.common import get_current_redis, get_latch
routes = Blueprint("inventory-data-job-routes", __name__) routes = Blueprint("inventory-data-job-routes", __name__)
logger = logging.getLogger(__name__)
@routes.after_request @routes.after_request
...@@ -65,3 +69,45 @@ def check_update_status(): ...@@ -65,3 +69,45 @@ def check_update_status():
task_id = task_id.decode('utf-8') task_id = task_id.decode('utf-8')
return jsonify(list(worker.check_task_status(task_id))) return jsonify(list(worker.check_task_status(task_id)))
LOG_ENTRY_SCHEMA = {
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"uuid": {"type": "string"},
"type": {"type": "string"},
"clock": {"type": "integer"}
},
"required": ["uuid", "type"],
"additionalProperties": True
}
@routes.route("log", methods=['GET', 'POST'])
@common.require_accepts_json
def load_task_log():
tasks = {}
# r = common.get_current_redis()
r = common.get_next_redis()
for k in r.scan_iter('joblog:*'):
value = r.get(k)
if not value:
logger.error(f'no data for log entry: {k.decode("utf-8")}')
continue
try:
value = json.loads(value.decode('utf-8'))
jsonschema.validate(value, LOG_ENTRY_SCHEMA)
except (json.JSONDecodeError, jsonschema.ValidationError):
logger.exception('error decoding entry for {k.decode("utf-8")}')
continue
info = tasks.setdefault(value['uuid'], {})
if value['type'] in ['task-info', 'task-warning', 'task-error']:
info.setdefault(value['type'], []).append(value)
else:
info[value['type']] = value
return jsonify(tasks)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment