From 4d825b7c0029ab6d7bfca03dbf284d3de78c4470 Mon Sep 17 00:00:00 2001 From: Jakob Langdal Date: Wed, 26 Apr 2023 10:50:44 +0000 Subject: [PATCH] Fix outside context calls when testing --- optimizerapi/optimizer.py | 10 +++++++--- optimizerapi/server.py | 4 ++-- requirements-freeze.txt | 2 +- requirements.txt | 1 + 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/optimizerapi/optimizer.py b/optimizerapi/optimizer.py index 224be4e..78fb785 100644 --- a/optimizerapi/optimizer.py +++ b/optimizerapi/optimizer.py @@ -45,9 +45,13 @@ def run(body) -> dict: dict a JSON encodable dictionary representation of the result. """ - if 'waitress.client_disconnected' in connexion.request.environ: - disconnect_check = connexion.request.environ['waitress.client_disconnected'] - else: + try: + if 'waitress.client_disconnected' in connexion.request.environ: + disconnect_check = connexion.request.environ['waitress.client_disconnected'] + else: + def disconnect_check(): + return False + except RuntimeError: def disconnect_check(): return False print(disconnect_check()) diff --git a/optimizerapi/server.py b/optimizerapi/server.py index 56ab783..a419807 100644 --- a/optimizerapi/server.py +++ b/optimizerapi/server.py @@ -12,7 +12,7 @@ # Initialize crypto get_crypto() app = connexion.FlaskApp( - __name__, port=9090, specification_dir="./openapi/") + __name__, specification_dir="./openapi/") app.add_api("specification.yml", strict_validation=True, validate_responses=True) @@ -53,6 +53,6 @@ print("CORS: disabled") if development: - app.run() + app.run(port=9090) else: serve(app, listen="*:9090", channel_request_lookahead=1) diff --git a/requirements-freeze.txt b/requirements-freeze.txt index ec656a0..1492875 100644 --- a/requirements-freeze.txt +++ b/requirements-freeze.txt @@ -22,7 +22,7 @@ itsdangerous==2.1.2 Jinja2==3.1.2 joblib==1.2.0 json-tricks==3.15.5 -jsonschema==4.17.3 +jsonschema==4.15.0 kiwisolver==1.4.4 MarkupSafe==2.1.2 matplotlib==3.5.3 diff --git a/requirements.txt b/requirements.txt index f43f0b9..8ac6117 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,6 +5,7 @@ Flask==2.2.3 Flask-Cors==3.0.10 ProcessOptimizer[browniebee]==0.8.0 json-tricks==3.15.5 +jsonschema==4.15.0 cryptography==3.4.7 waitress==2.1.2 rq==1.10.0