Compare commits

..

No commits in common. "05d9cdc7b1b34e03deedf825f81b26a85ce5c138" and "a2092465138aa1778a822130865b545892f03eb2" have entirely different histories.

View File

@ -1,4 +1,3 @@
import multiprocessing
import telebot
import threading
import time
@ -10,7 +9,7 @@ from utils import queues
class Daemon(base.Daemon):
def __init__(self):
self.telegram_bots: dict[str, dict[str, multiprocessing.Process|None]] = {}
self.telegram_bots: dict[str, dict[str, telebot.TeleBot|None]] = {}
def execute(self):
while True:
@ -23,26 +22,26 @@ class Daemon(base.Daemon):
self.telegram_bots[project_name][bot_name] = None
bot = self.telegram_bots[project_name][bot_name]
if bot_info.get('poll_enabled'):
if bot is not None and bot.is_alive:
if bot is not None:
print(f'process for {project_name} {bot_name} is alive')
continue
print(f'starting process for {project_name} {bot_name}')
bot = telebot.TeleBot(bot_info['secrets']['telegram_token'])
self.start_polling(bot, bot_info['queue'], project_name, bot_name)
self.start_polling(bot, bot_info['queue'])
self.telegram_bots[project_name][bot_name] = bot
print(f'started process for {project_name} {bot_name}')
else:
if bot is None:
print(f'process for {project_name} {bot_name} is not alive')
continue
print(f'terminating process for {project_name} {bot_name}')
bot.terminate()
bot.stop_bot()
self.telegram_bots[project_name][bot_name] = None
print(f'terminated process for {project_name} {bot_name}')
time.sleep(10)
def start_polling(self, bot: telebot.TeleBot, queue: str, project_name: str, bot_name: str):
def start_polling(self, bot: telebot.TeleBot, queue: str):
@bot.message_handler()
def do_action(message: telebot.types.Message):
queues.set_task(queue, message.json, 1)
process = multiprocessing.Process(target=bot.polling)
self.telegram_bots[project_name][bot_name] = process
threading.Thread(target=bot.polling).start()