diff --git a/kdb-bot/src/bot/application.py b/kdb-bot/src/bot/application.py index ca3e0976..13d46815 100644 --- a/kdb-bot/src/bot/application.py +++ b/kdb-bot/src/bot/application.py @@ -71,7 +71,7 @@ class Application(DiscordBotApplicationABC): self._api.stop() await self._bot.close() - self._data_integrity.check_data_integrity(is_for_shutdown=True) + await self._data_integrity.check_data_integrity(is_for_shutdown=True) self._logger.info(__name__, f"Stopped {DiscordBotService.__name__}") except Exception as e: self._logger.error(__name__, "stop failed", e) diff --git a/kdb-bot/src/bot_core/service/data_integrity_service.py b/kdb-bot/src/bot_core/service/data_integrity_service.py index 923cf4cb..973b1c0d 100644 --- a/kdb-bot/src/bot_core/service/data_integrity_service.py +++ b/kdb-bot/src/bot_core/service/data_integrity_service.py @@ -363,7 +363,7 @@ class DataIntegrityService: except Exception as e: self._logger.error(__name__, f"Cannot get UserJoinedGameServer", e) - def _check_for_user_achievements(self): + async def _check_for_user_achievements(self): self._logger.debug(__name__, f"Start checking UserGotAchievement table") for guild in self._bot.guilds: @@ -380,9 +380,9 @@ class DataIntegrityService: if user is None: self._logger.fatal(__name__, f"User not found in database: {member.id}") - self._bot.loop.create_task(self._achievements.validate_achievements_for_user(user)) + await self._achievements.validate_achievements_for_user(user) - def check_data_integrity(self, is_for_shutdown=False): + async def check_data_integrity(self, is_for_shutdown=False): if is_for_shutdown != self._is_for_shutdown: self._is_for_shutdown = is_for_shutdown @@ -393,4 +393,4 @@ class DataIntegrityService: self._check_user_joins() self._check_user_joins_vc() self._check_user_joined_gs() - self._check_for_user_achievements() + await self._check_for_user_achievements() diff --git a/kdb-bot/src/modules/database/database_on_ready_event.py b/kdb-bot/src/modules/database/database_on_ready_event.py index d895592d..5c3bd775 100644 --- a/kdb-bot/src/modules/database/database_on_ready_event.py +++ b/kdb-bot/src/modules/database/database_on_ready_event.py @@ -48,7 +48,7 @@ class DatabaseOnReadyEvent(OnReadyABC): async def on_ready(self): self._logger.debug(__name__, f"Module {type(self)} started") - self._data_integrity.check_data_integrity() + await self._data_integrity.check_data_integrity() await self._seeder.seed() self._validate_init_time() diff --git a/kdb-bot/src/modules/technician/command/restart_command.py b/kdb-bot/src/modules/technician/command/restart_command.py index 62029cec..003cdf9e 100644 --- a/kdb-bot/src/modules/technician/command/restart_command.py +++ b/kdb-bot/src/modules/technician/command/restart_command.py @@ -11,6 +11,7 @@ from bot_core.abc.client_utils_abc import ClientUtilsABC from bot_core.abc.message_service_abc import MessageServiceABC from bot_core.helper.command_checks import CommandChecks from bot_core.logging.command_logger import CommandLogger +from bot_core.service.data_integrity_service import DataIntegrityService from modules.permission.abc.permission_service_abc import PermissionServiceABC @@ -24,6 +25,7 @@ class RestartCommand(DiscordCommandABC): client_utils: ClientUtilsABC, translate: TranslatePipe, permissions: PermissionServiceABC, + data_integrity: DataIntegrityService, ): DiscordCommandABC.__init__(self) @@ -34,6 +36,7 @@ class RestartCommand(DiscordCommandABC): self._client_utils = client_utils self._t = translate self._permissions = permissions + self._data_integrity = data_integrity self._logger.trace(__name__, f"Loaded command service: {type(self).__name__}") @@ -48,6 +51,7 @@ class RestartCommand(DiscordCommandABC): await self._client_utils.presence_game("common.presence.restart") await self._message_service.send_ctx_msg(ctx, self._t.transform("modules.technician.restart_message")) await asyncio.sleep(self._settings.wait_for_restart) + await self._data_integrity.check_data_integrity(is_for_shutdown=True) await self._bot.stop_async() self._logger.trace(__name__, f"Finished restart command") diff --git a/kdb-bot/src/modules/technician/command/shutdown_command.py b/kdb-bot/src/modules/technician/command/shutdown_command.py index 44e01464..db2f807a 100644 --- a/kdb-bot/src/modules/technician/command/shutdown_command.py +++ b/kdb-bot/src/modules/technician/command/shutdown_command.py @@ -11,6 +11,7 @@ from bot_core.abc.client_utils_abc import ClientUtilsABC from bot_core.abc.message_service_abc import MessageServiceABC from bot_core.helper.command_checks import CommandChecks from bot_core.logging.command_logger import CommandLogger +from bot_core.service.data_integrity_service import DataIntegrityService from bot_data.model.technician_config import TechnicianConfig from modules.permission.abc.permission_service_abc import PermissionServiceABC @@ -26,6 +27,7 @@ class ShutdownCommand(DiscordCommandABC): translate: TranslatePipe, permissions: PermissionServiceABC, settings: TechnicianConfig, + data_integrity: DataIntegrityService, ): DiscordCommandABC.__init__(self) @@ -37,6 +39,7 @@ class ShutdownCommand(DiscordCommandABC): self._t = translate self._permissions = permissions self._settings = settings + self._data_integrity = data_integrity self._logger.trace(__name__, f"Loaded command service: {type(self).__name__}") @@ -50,6 +53,7 @@ class ShutdownCommand(DiscordCommandABC): await self._client_utils.presence_game("common.presence.shutdown") await self._message_service.send_ctx_msg(ctx, self._t.transform("modules.technician.shutdown_message")) await asyncio.sleep(self._settings.wait_for_shutdown) + await self._data_integrity.check_data_integrity(is_for_shutdown=True) await self._bot.stop_async() self._logger.trace(__name__, f"Finished shutdown command")