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

return 503 to /jobs/update if an update is pending

parent 3f7cad3a
No related branches found
No related tags found
No related merge requests found
from flask import Blueprint, current_app, jsonify
from flask import Blueprint, current_app, jsonify, Response
from inventory_provider.tasks import worker
from inventory_provider.routes import common
from inventory_provider.tasks.common import get_current_redis, get_latch
routes = Blueprint("inventory-data-job-routes", __name__)
......@@ -13,6 +14,15 @@ def after_request(resp):
@routes.route("/update", methods=['GET', 'POST'])
@common.require_accepts_json
def update():
config = current_app.config['INVENTORY_PROVIDER_CONFIG']
latch = get_latch(get_current_redis(config))
if latch and latch['pending']:
return Response(
response='an update is already in progress',
status=503,
mimetype="text/html")
job_ids = worker.launch_refresh_cache_all(
current_app.config["INVENTORY_PROVIDER_CONFIG"])
return jsonify(job_ids)
......
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