From 66c8cd48903f61c1c8afd4f967a7fb0edbd32093 Mon Sep 17 00:00:00 2001 From: Erik Reid <erik.reid@geant.org> Date: Thu, 14 Nov 2019 16:37:40 +0100 Subject: [PATCH] return 503 to /jobs/update if an update is pending --- inventory_provider/routes/jobs.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/inventory_provider/routes/jobs.py b/inventory_provider/routes/jobs.py index b4b5acea..c9234fbc 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) -- GitLab