From e8c491a47836ff6185e402a72dd43d70bafd292a Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Fri, 14 Oct 2022 07:16:12 +0200 Subject: [PATCH] Made api async #70 --- src/bot/application.py | 1 + src/bot_api/api_thread.py | 2 +- src/bot_api/bot-api.json | 2 +- src/bot_api/controller/api_controller.py | 6 +++--- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/bot/application.py b/src/bot/application.py index c557eace..726cdbdb 100644 --- a/src/bot/application.py +++ b/src/bot/application.py @@ -47,6 +47,7 @@ class Application(DiscordBotApplicationABC): self._api.start() if self._feature_flags.get_flag(FeatureFlagsEnum.api_only): + self._api.join() return self._logger.trace(__name__, f'Try to start {DiscordBotService.__name__}') diff --git a/src/bot_api/api_thread.py b/src/bot_api/api_thread.py index b6a34bde..f3ecf6cc 100644 --- a/src/bot_api/api_thread.py +++ b/src/bot_api/api_thread.py @@ -14,7 +14,7 @@ class ApiThread(threading.Thread): api: Api, feature_flags: FeatureFlagsSettings ): - threading.Thread.__init__(self, daemon=not feature_flags.get_flag(FeatureFlagsEnum.api_only)) + threading.Thread.__init__(self, daemon=True) self._logger = logger self._api = api diff --git a/src/bot_api/bot-api.json b/src/bot_api/bot-api.json index b31234fd..09e41293 100644 --- a/src/bot_api/bot-api.json +++ b/src/bot_api/bot-api.json @@ -17,7 +17,7 @@ "LicenseDescription": "", "Dependencies": [ "cpl-core==2022.10.0.post6", - "Flask==2.2.2", + "Flask[async]==2.2.2", "Flask-Classful==0.14.2" ], "DevDependencies": [ diff --git a/src/bot_api/controller/api_controller.py b/src/bot_api/controller/api_controller.py index e17103e6..1b7ae669 100644 --- a/src/bot_api/controller/api_controller.py +++ b/src/bot_api/controller/api_controller.py @@ -33,13 +33,13 @@ class ApiController: self._mailer = mailer @Route.route('/api/api-version') - def api_version(self): + async def api_version(self): import bot_api version = bot_api.version_info return VersionDTO(version.major, version.minor, version.micro).to_dict() @Route.route('/api/settings') - def settings(self): + async def settings(self): # TODO: Authentication import bot_api version = bot_api.version_info @@ -60,7 +60,7 @@ class ApiController: ).to_dict() @Route.route('/api/send-test-mail/') - def send_test_mail(self, email: str): + async def send_test_mail(self, email: str): # TODO: Authentication mail = EMail() mail.add_header('Mime-Version: 1.0')