40 lines
1013 B
Python
40 lines
1013 B
Python
|
|
"""Celery worker configuration."""
|
||
|
|
from celery import Celery
|
||
|
|
from celery.schedules import crontab
|
||
|
|
from app.config import settings
|
||
|
|
|
||
|
|
# Create Celery app
|
||
|
|
celery_app = Celery(
|
||
|
|
'pension_quant',
|
||
|
|
broker=settings.celery_broker_url,
|
||
|
|
backend=settings.celery_result_backend
|
||
|
|
)
|
||
|
|
|
||
|
|
# Celery configuration
|
||
|
|
celery_app.conf.update(
|
||
|
|
task_serializer='json',
|
||
|
|
accept_content=['json'],
|
||
|
|
result_serializer='json',
|
||
|
|
timezone='Asia/Seoul',
|
||
|
|
enable_utc=True,
|
||
|
|
task_track_started=True,
|
||
|
|
task_time_limit=3600, # 1 hour
|
||
|
|
worker_prefetch_multiplier=1,
|
||
|
|
worker_max_tasks_per_child=1000,
|
||
|
|
)
|
||
|
|
|
||
|
|
# Celery Beat schedule
|
||
|
|
celery_app.conf.beat_schedule = {
|
||
|
|
'collect-daily-data': {
|
||
|
|
'task': 'app.tasks.data_collection.collect_all_data',
|
||
|
|
'schedule': crontab(
|
||
|
|
hour=settings.data_collection_hour,
|
||
|
|
minute=settings.data_collection_minute,
|
||
|
|
day_of_week='1-5' # Monday to Friday
|
||
|
|
),
|
||
|
|
},
|
||
|
|
}
|
||
|
|
|
||
|
|
# Auto-discover tasks
|
||
|
|
celery_app.autodiscover_tasks(['app.tasks'])
|