"settings.py"
CELERY_BROKER_URL = 'redis://localhost:6379'
CELERY_RESULT_BACKEND = 'redis://localhost:6379'
CELERY_ACCEPT_CONTENT = ['application/json']
CELERY_RESULT_SERIALIZER = 'json'
CELERY_TASK_SERIALIZER = 'json'
"celeryapp.py"
from __future__ import absolute_import, unicode_literals
import os
from celery import Celery
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'oko.settings')
celery_app = Celery()
celery_app.config_from_object('django.conf:settings', namespace='CELERY')
celery_app.autodiscover_tasks()
"tasks.py"
from celery import shared_task
@shared_task
def main_loop(date2load: str = None):
# Завантаження конфігурації із файлу
...
@shared_task
def search_pub(line):
....
CELERY_ROUTES = {
'main_loop': {'queue': 'queue1'},
'search_pub': {'queue': 'queue2'},
}
CELERY_QUEUES = (
Queue('default', Exchange('default'), routing_key='default'),
Queue('queue1', Exchange('queue1'), routing_key='queue1'),
Queue('queue2', Exchange('queue2'), routing_key='queue2'),
)/code>
вот <a href="https://docs.celeryproject.org/en/latest/userguide/routing.html">тут</a> есть все подробности