"Update routing config" (#25536)
* Revert "Revert "Update routing config" * Removed settings from lms/celery.py and cms/celery.py * Moved settings import from top-level to function's scopes Co-authored-by: Soban Javed <iamsobanjaved@gmail.com>
This commit is contained in:
@@ -10,7 +10,7 @@ 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', 'cms.envs.production')
|
||||
@@ -23,34 +23,12 @@ 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 }
|
||||
"""
|
||||
# The tasks below will be routed to the default lms queue.
|
||||
return {
|
||||
'completion_aggregator.tasks.update_aggregators': 'lms',
|
||||
'openedx.core.djangoapps.content.block_structure.tasks.update_course_in_cache': 'lms',
|
||||
'openedx.core.djangoapps.content.block_structure.tasks.update_course_in_cache_v2': 'lms',
|
||||
}
|
||||
|
||||
@property
|
||||
def explicit_queues(self):
|
||||
"""
|
||||
Defines specific queues for tasks to run in (typically outside of the cms environment),
|
||||
as a dict of form { task_name: queue_name }.
|
||||
"""
|
||||
return {
|
||||
'lms.djangoapps.grades.tasks.compute_all_grades_for_course': settings.POLICY_CHANGE_GRADES_ROUTING_KEY,
|
||||
}
|
||||
return route_task_queue(name)
|
||||
|
||||
Reference in New Issue
Block a user