fix
This commit is contained in:
parent
e7ce0cb6af
commit
03fcd8894b
@ -1,3 +1,4 @@
|
||||
import multiprocessing
|
||||
import telebot
|
||||
import threading
|
||||
import time
|
||||
@ -9,7 +10,7 @@ from utils import queues
|
||||
|
||||
class Daemon(base.Daemon):
|
||||
def __init__(self):
|
||||
self.telegram_bots: dict[str, dict[str, telebot.TeleBot|None]] = {}
|
||||
self.telegram_bots: dict[str, dict[str, multiprocessing.Process|None]] = {}
|
||||
|
||||
def execute(self):
|
||||
while True:
|
||||
@ -22,26 +23,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:
|
||||
if bot is not None and bot.is_alive:
|
||||
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'])
|
||||
self.telegram_bots[project_name][bot_name] = bot
|
||||
self.start_polling(bot, bot_info['queue'], project_name, bot_name)
|
||||
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.stop_bot()
|
||||
bot.terminate()
|
||||
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):
|
||||
def start_polling(self, bot: telebot.TeleBot, queue: str, project_name: str, bot_name: str):
|
||||
@bot.message_handler()
|
||||
def do_action(message: telebot.types.Message):
|
||||
queues.set_task(queue, message.json, 1)
|
||||
threading.Thread(target=bot.polling).start()
|
||||
process = multiprocessing.Process(target=bot.polling)
|
||||
self.telegram_bots[project_name][bot_name] = process
|
||||
|
Loading…
Reference in New Issue
Block a user