From 5c6426699191b27d69c30ea176d3bf7549af5547 Mon Sep 17 00:00:00 2001 From: David Trattnig <david.trattnig@o94.at> Date: Thu, 25 Jun 2020 18:50:30 +0200 Subject: [PATCH] Wiring service via app context. --- src/app.py | 7 ++++--- src/rest/controllers/internal_controller.py | 8 ++++++++ src/rest/controllers/public_controller.py | 6 ++++-- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/app.py b/src/app.py index ca700fc..5100588 100644 --- a/src/app.py +++ b/src/app.py @@ -49,8 +49,8 @@ def build_app(app): ma.init_app(app) return app -api = connexion.App(__name__, specification_dir='rest/swagger') -api.add_api('swagger.yaml', arguments={'title': 'AURA Engine API'}, pythonic_params=True) +api = connexion.App(__name__, specification_dir='rest/swagger', arguments={'title': 'AURA Engine API'}) +api.add_api('swagger.yaml', pythonic_params=True) app = build_app(api.app) @@ -68,7 +68,8 @@ with app.app_context(): """ db.create_all() service = ApiService(config, logger) - logger.info("API server initialized.") + app.config['SERVICE'] = service + logger.info("Engine API server initialized.") if __name__ == '__main__': diff --git a/src/rest/controllers/internal_controller.py b/src/rest/controllers/internal_controller.py index 845f9df..fc837a1 100644 --- a/src/rest/controllers/internal_controller.py +++ b/src/rest/controllers/internal_controller.py @@ -7,6 +7,8 @@ from src.rest.models.play_log_entry import PlayLogEntry # noqa: E501 from src.rest.models.status_entry import StatusEntry # noqa: E501 from src.rest import util +from flask import current_app + def activate_engine(engine_number): # noqa: E501 """Set active engine @@ -18,6 +20,7 @@ def activate_engine(engine_number): # noqa: E501 :rtype: None """ + service = current_app.config['SERVICE'] return 'do some magic!' @@ -29,6 +32,7 @@ def clock_info(): # noqa: E501 :rtype: ClockInfo """ + service = current_app.config['SERVICE'] return 'do some magic!' @@ -40,6 +44,7 @@ def get_active_engine(): # noqa: E501 :rtype: StatusEntry """ + service = current_app.config['SERVICE'] return 'do some magic!' @@ -53,6 +58,7 @@ def get_engine_health(engine_number): # noqa: E501 :rtype: HealthInfo """ + service = current_app.config['SERVICE'] return 'do some magic!' @@ -66,6 +72,7 @@ def get_report(year_month): # noqa: E501 :rtype: List[PlayLogEntry] """ + service = current_app.config['SERVICE'] return 'do some magic!' @@ -79,4 +86,5 @@ def log_engine_health(engine_number): # noqa: E501 :rtype: None """ + service = current_app.config['SERVICE'] return 'do some magic!' diff --git a/src/rest/controllers/public_controller.py b/src/rest/controllers/public_controller.py index 104ba1e..d0e2870 100644 --- a/src/rest/controllers/public_controller.py +++ b/src/rest/controllers/public_controller.py @@ -6,6 +6,8 @@ import six from src.rest.models.play_log_entry import PlayLogEntry # noqa: E501 from src.rest import util +from flask import current_app + def current_track(): # noqa: E501 """Get current track @@ -15,7 +17,7 @@ def current_track(): # noqa: E501 :rtype: PlayLogEntry """ - from src.app import service + service = current_app.config['SERVICE'] return service.current_track() @@ -31,5 +33,5 @@ def list_tracks(offset=None, limit=None): # noqa: E501 :rtype: List[PlayLogEntry] """ - from src.app import service + service = current_app.config['SERVICE'] return service.list_tracks(offset, limit) \ No newline at end of file -- GitLab