fix
This commit is contained in:
parent
2506b7a7a0
commit
ba6b903c57
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user