Fixed shutdown procedure async problems #1.1.0.rc2
This commit is contained in:
parent
44f6b36347
commit
caeec47b7c
@ -71,7 +71,7 @@ class Application(DiscordBotApplicationABC):
|
|||||||
self._api.stop()
|
self._api.stop()
|
||||||
|
|
||||||
await self._bot.close()
|
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__}")
|
self._logger.info(__name__, f"Stopped {DiscordBotService.__name__}")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self._logger.error(__name__, "stop failed", e)
|
self._logger.error(__name__, "stop failed", e)
|
||||||
|
@ -363,7 +363,7 @@ class DataIntegrityService:
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
self._logger.error(__name__, f"Cannot get UserJoinedGameServer", 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")
|
self._logger.debug(__name__, f"Start checking UserGotAchievement table")
|
||||||
|
|
||||||
for guild in self._bot.guilds:
|
for guild in self._bot.guilds:
|
||||||
@ -380,9 +380,9 @@ class DataIntegrityService:
|
|||||||
if user is None:
|
if user is None:
|
||||||
self._logger.fatal(__name__, f"User not found in database: {member.id}")
|
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:
|
if is_for_shutdown != self._is_for_shutdown:
|
||||||
self._is_for_shutdown = is_for_shutdown
|
self._is_for_shutdown = is_for_shutdown
|
||||||
|
|
||||||
@ -393,4 +393,4 @@ class DataIntegrityService:
|
|||||||
self._check_user_joins()
|
self._check_user_joins()
|
||||||
self._check_user_joins_vc()
|
self._check_user_joins_vc()
|
||||||
self._check_user_joined_gs()
|
self._check_user_joined_gs()
|
||||||
self._check_for_user_achievements()
|
await self._check_for_user_achievements()
|
||||||
|
@ -48,7 +48,7 @@ class DatabaseOnReadyEvent(OnReadyABC):
|
|||||||
async def on_ready(self):
|
async def on_ready(self):
|
||||||
self._logger.debug(__name__, f"Module {type(self)} started")
|
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()
|
await self._seeder.seed()
|
||||||
|
|
||||||
self._validate_init_time()
|
self._validate_init_time()
|
||||||
|
@ -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.abc.message_service_abc import MessageServiceABC
|
||||||
from bot_core.helper.command_checks import CommandChecks
|
from bot_core.helper.command_checks import CommandChecks
|
||||||
from bot_core.logging.command_logger import CommandLogger
|
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
|
from modules.permission.abc.permission_service_abc import PermissionServiceABC
|
||||||
|
|
||||||
|
|
||||||
@ -24,6 +25,7 @@ class RestartCommand(DiscordCommandABC):
|
|||||||
client_utils: ClientUtilsABC,
|
client_utils: ClientUtilsABC,
|
||||||
translate: TranslatePipe,
|
translate: TranslatePipe,
|
||||||
permissions: PermissionServiceABC,
|
permissions: PermissionServiceABC,
|
||||||
|
data_integrity: DataIntegrityService,
|
||||||
):
|
):
|
||||||
DiscordCommandABC.__init__(self)
|
DiscordCommandABC.__init__(self)
|
||||||
|
|
||||||
@ -34,6 +36,7 @@ class RestartCommand(DiscordCommandABC):
|
|||||||
self._client_utils = client_utils
|
self._client_utils = client_utils
|
||||||
self._t = translate
|
self._t = translate
|
||||||
self._permissions = permissions
|
self._permissions = permissions
|
||||||
|
self._data_integrity = data_integrity
|
||||||
|
|
||||||
self._logger.trace(__name__, f"Loaded command service: {type(self).__name__}")
|
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._client_utils.presence_game("common.presence.restart")
|
||||||
await self._message_service.send_ctx_msg(ctx, self._t.transform("modules.technician.restart_message"))
|
await self._message_service.send_ctx_msg(ctx, self._t.transform("modules.technician.restart_message"))
|
||||||
await asyncio.sleep(self._settings.wait_for_restart)
|
await asyncio.sleep(self._settings.wait_for_restart)
|
||||||
|
await self._data_integrity.check_data_integrity(is_for_shutdown=True)
|
||||||
await self._bot.stop_async()
|
await self._bot.stop_async()
|
||||||
|
|
||||||
self._logger.trace(__name__, f"Finished restart command")
|
self._logger.trace(__name__, f"Finished restart command")
|
||||||
|
@ -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.abc.message_service_abc import MessageServiceABC
|
||||||
from bot_core.helper.command_checks import CommandChecks
|
from bot_core.helper.command_checks import CommandChecks
|
||||||
from bot_core.logging.command_logger import CommandLogger
|
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 bot_data.model.technician_config import TechnicianConfig
|
||||||
from modules.permission.abc.permission_service_abc import PermissionServiceABC
|
from modules.permission.abc.permission_service_abc import PermissionServiceABC
|
||||||
|
|
||||||
@ -26,6 +27,7 @@ class ShutdownCommand(DiscordCommandABC):
|
|||||||
translate: TranslatePipe,
|
translate: TranslatePipe,
|
||||||
permissions: PermissionServiceABC,
|
permissions: PermissionServiceABC,
|
||||||
settings: TechnicianConfig,
|
settings: TechnicianConfig,
|
||||||
|
data_integrity: DataIntegrityService,
|
||||||
):
|
):
|
||||||
DiscordCommandABC.__init__(self)
|
DiscordCommandABC.__init__(self)
|
||||||
|
|
||||||
@ -37,6 +39,7 @@ class ShutdownCommand(DiscordCommandABC):
|
|||||||
self._t = translate
|
self._t = translate
|
||||||
self._permissions = permissions
|
self._permissions = permissions
|
||||||
self._settings = settings
|
self._settings = settings
|
||||||
|
self._data_integrity = data_integrity
|
||||||
|
|
||||||
self._logger.trace(__name__, f"Loaded command service: {type(self).__name__}")
|
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._client_utils.presence_game("common.presence.shutdown")
|
||||||
await self._message_service.send_ctx_msg(ctx, self._t.transform("modules.technician.shutdown_message"))
|
await self._message_service.send_ctx_msg(ctx, self._t.transform("modules.technician.shutdown_message"))
|
||||||
await asyncio.sleep(self._settings.wait_for_shutdown)
|
await asyncio.sleep(self._settings.wait_for_shutdown)
|
||||||
|
await self._data_integrity.check_data_integrity(is_for_shutdown=True)
|
||||||
await self._bot.stop_async()
|
await self._bot.stop_async()
|
||||||
|
|
||||||
self._logger.trace(__name__, f"Finished shutdown command")
|
self._logger.trace(__name__, f"Finished shutdown command")
|
||||||
|
Loading…
Reference in New Issue
Block a user