diff --git a/site/app.py b/site/app.py index 800b58b..d794e7a 100644 --- a/site/app.py +++ b/site/app.py @@ -32,7 +32,7 @@ from routes.api_scenario_defs import bp_defs as api_scenario_defs_bp # Версия — показывается в топбаре UI. Меняется при КАЖДОМ изменении кода. # Нужна для фильтрации истории (пользователь видит только записи своей версии). -VERSION = "1.2.22" +VERSION = "1.2.23" # Flask-приложение с Jinja2-шаблонами из папки templates/ app = Flask(__name__, template_folder="templates", static_folder="static") diff --git a/site/db/scenario_defs.py b/site/db/scenario_defs.py index 3d4f859..a1a8a4e 100644 --- a/site/db/scenario_defs.py +++ b/site/db/scenario_defs.py @@ -215,10 +215,11 @@ def lock_check(client_id, stand): Returns: True — можно запускать (нет RUNNING в БД) - False — нельзя (уже есть RUNNING) → 409 Conflict""" + False — нельзя (уже есть RUNNING) → 409 Conflict + None — БД недоступна, нельзя проверить → 503 DB unavailable""" conn = get_conn() if not conn: - return False # без БД — не разрешаем (partial unique index недоступен) + return None # БД недоступна — не True и не False, вызывающий решит try: cur = conn.cursor() cur.execute(""" @@ -231,7 +232,6 @@ def lock_check(client_id, stand): return row is None # None = нет RUNNING = можно запускать except Exception as e: print(f"[DEFS] lock_check error: {e}", flush=True) - # При ошибке БД — НЕ разрешаем (безопасный fallback) - return False + return None # ошибка БД — не можем проверить finally: put_conn(conn) diff --git a/site/routes/api_scenario_run.py b/site/routes/api_scenario_run.py index cde72c2..8784891 100644 --- a/site/routes/api_scenario_run.py +++ b/site/routes/api_scenario_run.py @@ -41,7 +41,10 @@ def api_scenario_run(): cid = get_client_id() stand = get_stand() - if not lock_check(cid, stand): + can_run = lock_check(cid, stand) + if can_run is None: + return jsonify({"error": "DB unavailable"}), 503 + if not can_run: return jsonify({"error": "Another scenario is already running"}), 409 defn = get_definition(def_id, cid, stand)