From ba6b903c571337b0b81370cb2e7a3abd40275624 Mon Sep 17 00:00:00 2001 From: emmatveev Date: Wed, 27 Nov 2024 04:10:50 +0300 Subject: [PATCH] fix --- daemons/poll.py | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/daemons/poll.py b/daemons/poll.py index 362ec52..31df367 100644 --- a/daemons/poll.py +++ b/daemons/poll.py @@ -12,27 +12,28 @@ class Daemon(base.Daemon): self.telegram_pollers: dict[str, dict[str, multiprocessing.Process|None]] = {} def execute(self): - bots = platform.platform_client.get_config('bots') - for project_name, project in bots.items(): - if project_name not in self.telegram_pollers: - self.telegram_pollers[project_name] = {} - for bot_name, bot_info in project.items(): - if bot_name not in self.telegram_pollers[project_name]: - self.telegram_pollers[project_name][bot_name] = None - process = self.telegram_pollers[project_name][bot_name] - if bot_info.get('poll_enabled'): - if process is not None and process.is_alive: - continue - new_process = multiprocessing.Process(target=self.start_polling, args=[bot_info['secrets']['telegram_token'], bot_info['queue']]) - new_process.start() - self.telegram_pollers[project_name][bot_name] = new_process - else: - if process is None: - continue - if process.is_alive: - process.terminate() + while True: + bots = platform.platform_client.get_config('bots') + for project_name, project in bots.items(): + if project_name not in self.telegram_pollers: + self.telegram_pollers[project_name] = {} + for bot_name, bot_info in project.items(): + if bot_name not in self.telegram_pollers[project_name]: self.telegram_pollers[project_name][bot_name] = None - time.sleep(10) + process = self.telegram_pollers[project_name][bot_name] + if bot_info.get('poll_enabled'): + if process is not None and process.is_alive: + continue + new_process = multiprocessing.Process(target=self.start_polling, args=[bot_info['secrets']['telegram_token'], bot_info['queue']]) + new_process.start() + self.telegram_pollers[project_name][bot_name] = new_process + else: + if process is None: + continue + if process.is_alive: + process.terminate() + self.telegram_pollers[project_name][bot_name] = None + time.sleep(10) def start_polling(telegram_token, queue): bot = telebot.TeleBot(telegram_token)