diff --git a/inventory_provider/routes/jobs.py b/inventory_provider/routes/jobs.py index b4b5acea983dbdc890a3c2a8cce1991adcbc8dcb..c9234fbc724577aa0d5b744eef3aa3af8f0e107c 100644 --- a/inventory_provider/routes/jobs.py +++ b/inventory_provider/routes/jobs.py @@ -1,6 +1,7 @@ -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)