init commit

This commit is contained in:
2025-12-18 05:55:32 +09:00
commit a6817e487e
72 changed files with 13847 additions and 0 deletions

39
app/celery_config.py Normal file
View File

@@ -0,0 +1,39 @@
"""
Celery конфигурация для асинхронных задач
"""
from celery import Celery
from app.settings import Config
import logging
logger = logging.getLogger(__name__)
# Создать Celery приложение
celery_app = Celery(
'tg_autoposter',
broker=Config.CELERY_BROKER_URL,
backend=Config.CELERY_RESULT_BACKEND_URL
)
# Конфигурация
celery_app.conf.update(
task_serializer='json',
accept_content=['json'],
result_serializer='json',
timezone='UTC',
enable_utc=True,
task_track_started=True,
task_time_limit=30 * 60, # 30 минут жесткий лимит
task_soft_time_limit=25 * 60, # 25 минут мягкий лимит
worker_prefetch_multiplier=1, # Брать по одной задаче
worker_max_tasks_per_child=1000, # Перезагружать worker после 1000 задач
)
# Маршруты для задач
celery_app.conf.task_routes = {
'app.celery_tasks.send_message_task': {'queue': 'messages'},
'app.celery_tasks.parse_group_members_task': {'queue': 'parsing'},
'app.celery_tasks.cleanup_old_messages_task': {'queue': 'maintenance'},
}
logger.info("✅ Celery инициализирован")