Fixed shutdown procedure async problems #1.1.0.rc2

This commit is contained in:
Sven Heidemann 2023-08-16 18:04:40 +02:00
parent 44f6b36347
commit caeec47b7c
5 changed files with 14 additions and 6 deletions

View File

@ -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)

View File

@ -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()

View File

@ -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()

View File

@ -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")

View File

@ -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")