diff --git a/src/app.py b/src/app.py index ca700fc2f444ac61e2197ee2863fb86aeb076c7e..5100588fd12c5ddb3dd0f265a9e4ebea9a4689d9 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 845f9df47536e7ad8b325c1477e565433731eb1a..fc837a19525de9c874be7accd1b39e8a50c24261 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 104ba1e4970738cc06f7650a0d0826c34d920fa6..d0e287016fa71f40518a027a57772391399f1e43 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