Answer the question
In order to leave comments, you need to log in
How to split two tasks into Celery queues in Django? What needs to be changed?
"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):
....
Answer the question
In order to leave comments, you need to log in
in settings.py something like this:
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> есть все подробности
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question