Added data integrity check to shutdown #292_shutdown_procedure

This commit is contained in:
Sven Heidemann 2023-06-14 09:29:07 +02:00
parent ff16eae477
commit f034413e35
2 changed files with 3 additions and 1 deletions

View File

@ -10,6 +10,7 @@ from cpl_translation import TranslatePipe, TranslationServiceABC, TranslationSet
from bot_api.api_thread import ApiThread from bot_api.api_thread import ApiThread
from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum
from bot_core.configuration.feature_flags_settings import FeatureFlagsSettings from bot_core.configuration.feature_flags_settings import FeatureFlagsSettings
from bot_core.service.data_integrity_service import DataIntegrityService
class Application(DiscordBotApplicationABC): class Application(DiscordBotApplicationABC):
@ -21,6 +22,7 @@ class Application(DiscordBotApplicationABC):
# cpl-core # cpl-core
self._logger: LoggerABC = services.get_service(LoggerABC) self._logger: LoggerABC = services.get_service(LoggerABC)
self._data_integrity: DataIntegrityService = services.get_service(DataIntegrityService)
# cpl-discord # cpl-discord
self._bot: DiscordBotServiceABC = services.get_service(DiscordBotServiceABC) self._bot: DiscordBotServiceABC = services.get_service(DiscordBotServiceABC)
self._bot_settings: DiscordBotSettings = config.get_configuration(DiscordBotSettings) self._bot_settings: DiscordBotSettings = config.get_configuration(DiscordBotSettings)
@ -68,6 +70,7 @@ class Application(DiscordBotApplicationABC):
if self._feature_flags.get_flag(FeatureFlagsEnum.api_module): if self._feature_flags.get_flag(FeatureFlagsEnum.api_module):
self._api.stop() self._api.stop()
self._data_integrity.check_data_integrity(is_for_shutdown=True)
await self._bot.close() await self._bot.close()
self._logger.info(__name__, f"Stopped {DiscordBotService.__name__}") self._logger.info(__name__, f"Stopped {DiscordBotService.__name__}")
except Exception as e: except Exception as e:

View File

@ -307,7 +307,6 @@ class DataIntegrityService:
join = UserJoinedVoiceChannel(user, member.voice.channel.id, datetime.now()) join = UserJoinedVoiceChannel(user, member.voice.channel.id, datetime.now())
self._user_joins_vc.add_user_joined_voice_channel(join) self._user_joins_vc.add_user_joined_voice_channel(join)
self._db_context.save_changes() self._db_context.save_changes()
self._logger.warn(__name__, f"VS {member.voice}")
except Exception as e: except Exception as e:
self._logger.error(__name__, f"Cannot get UserJoinedVoiceChannel", e) self._logger.error(__name__, f"Cannot get UserJoinedVoiceChannel", e)