diff --git a/backups/backup_2025-08-08_11-37-33.sql b/backups/backup_2025-08-08_11-37-33.sql new file mode 100644 index 0000000..5fa3352 --- /dev/null +++ b/backups/backup_2025-08-08_11-37-33.sql @@ -0,0 +1,28 @@ +/*M!999999\- enable the sandbox mode */ +-- MariaDB dump 10.19-11.6.2-MariaDB, for debian-linux-gnu (x86_64) +-- +-- Host: 127.0.0.1 Database: tg_autopost +-- ------------------------------------------------------ +-- Server version 11.6.2-MariaDB-ubu2404-log + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8mb4 */; +/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; +/*!40103 SET TIME_ZONE='+00:00' */; +/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*M!100616 SET @OLD_NOTE_VERBOSITY=@@NOTE_VERBOSITY, NOTE_VERBOSITY=0 */; +/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; + +/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; +/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; +/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; +/*M!100616 SET NOTE_VERBOSITY=@OLD_NOTE_VERBOSITY */; + +-- Dump completed on 2025-08-08 11:37:37 diff --git a/bot/management/commands/runbot.py b/bot/management/commands/runbot.py index 57008af..11f0beb 100644 --- a/bot/management/commands/runbot.py +++ b/bot/management/commands/runbot.py @@ -1,7 +1,8 @@ -# bot/management/commands/runbots.py import asyncio import logging import signal +from typing import Sequence + from django.core.management.base import BaseCommand from bot.models import TelegramBot from bot.bot_factory import build_application_for_bot @@ -13,27 +14,27 @@ class Command(BaseCommand): def handle(self, *args, **options): logging.basicConfig(level=logging.INFO, format="%(asctime)s %(levelname)s %(name)s: %(message)s") - asyncio.run(self._amain()) - async def _amain(self): - bots = list(TelegramBot.objects.filter(is_active=True)) + # ORM здесь, в синхронном контексте + bots: Sequence[TelegramBot] = list(TelegramBot.objects.filter(is_active=True)) if not bots: self.stderr.write(self.style.ERROR("Нет активных ботов (is_active=True).")) return + asyncio.run(self._amain(bots)) + + async def _amain(self, bots: Sequence[TelegramBot]): apps = [] try: - # Инициализация и старт polling для каждого бота for tb in bots: app, allowed_updates = build_application_for_bot(tb) await app.initialize() await app.start() - # в 22.x polling запускается через updater await app.updater.start_polling(allowed_updates=allowed_updates) apps.append(app) log.info("Bot started: %s (@%s)", tb.name, tb.username or "—") - # Ожидание сигнала остановки + # Ждём SIGINT/SIGTERM stop_event = asyncio.Event() def _stop(*_): @@ -44,13 +45,11 @@ class Command(BaseCommand): try: loop.add_signal_handler(sig, _stop) except NotImplementedError: - # Windows - pass + pass # Windows await stop_event.wait() finally: - # Корректная остановка всех приложений for app in reversed(apps): try: await app.updater.stop() diff --git a/db_storage/mysql/aria_log.00000001 b/db_storage/mysql/aria_log.00000001 index 5e45bf9..7271c8a 100644 Binary files a/db_storage/mysql/aria_log.00000001 and b/db_storage/mysql/aria_log.00000001 differ diff --git a/db_storage/mysql/aria_log_control b/db_storage/mysql/aria_log_control index 96193dc..9bde0de 100644 Binary files a/db_storage/mysql/aria_log_control and b/db_storage/mysql/aria_log_control differ