M
M
MOV_UA2020-01-25 16:01:21
Django
MOV_UA, 2020-01-25 16:01:21

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

3 answer(s)
V
Vadim Shatalov, 2020-01-25
@netpastor

docs.celeryproject.org/en/latest/userguide/routing.html

A
Andrey Leonov, 2020-01-25
@me-laman

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> есть все подробности

M
MOV_UA, 2020-01-25
@MOV_UA

Solved by using a different decorator @celery_app.task(queue='normal')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question