Update celery routing
- Used routing function istead of class - Move task queues to Djano settings - Removed routing_key parameter
This commit is contained in:
@@ -5,12 +5,11 @@ and auto discover tasks in all installed django apps.
|
||||
Taken from: https://celery.readthedocs.org/en/latest/django/first-steps-with-django.html
|
||||
"""
|
||||
|
||||
|
||||
import os
|
||||
|
||||
from celery import Celery
|
||||
|
||||
from openedx.core.lib.celery.routers import AlternateEnvironmentRouter
|
||||
from openedx.core.lib.celery.routers import route_task_queue
|
||||
|
||||
# set the default Django settings module for the 'celery' program.
|
||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'lms.envs.production')
|
||||
@@ -23,15 +22,16 @@ APP.conf.task_protocol = 1
|
||||
APP.config_from_object('django.conf:settings')
|
||||
APP.autodiscover_tasks()
|
||||
|
||||
# Import after autodiscovery has had a chance to connect to the import_module signal
|
||||
# so celery doesn't miss any apps getting installed.
|
||||
from django.conf import settings # pylint: disable=wrong-import-position,wrong-import-order
|
||||
|
||||
class Router(AlternateEnvironmentRouter):
|
||||
|
||||
def route_task(name, args, kwargs, options, task=None, **kw): # pylint: disable=unused-argument
|
||||
"""
|
||||
An implementation of AlternateEnvironmentRouter, for routing tasks to non-cms queues.
|
||||
Celery-defined method allowing for custom routing logic.
|
||||
|
||||
If None is returned from this method, default routing logic is used.
|
||||
"""
|
||||
|
||||
@property
|
||||
def alternate_env_tasks(self):
|
||||
"""
|
||||
Defines alternate environment tasks, as a dict of form { task_name: alternate_queue }
|
||||
"""
|
||||
return {}
|
||||
return route_task_queue(name, settings.EXPLICIT_QUEUES, settings.ALTERNATE_ENV_TASKS)
|
||||
|
||||
Reference in New Issue
Block a user