40 lines
1.2 KiB
Python
40 lines
1.2 KiB
Python
"""
|
|
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 инициализирован")
|