Skip to content

Commit d21649c

Browse files
committed
Ability to override the creation of the Celery App
1 parent a79534b commit d21649c

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

readthedocs/core/utils/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
from future.backports.urllib.parse import urlparse
1717
from celery import group, chord
1818

19-
from ..tasks import send_email_task
2019
from readthedocs.builds.constants import LATEST
2120
from readthedocs.doc_builder.constants import DOCKER_LIMITS
2221

@@ -144,10 +143,13 @@ def send_email(recipient, subject, template, template_html, context=None,
144143
Task :py:func:`readthedocs.core.tasks.send_email_task`
145144
Task that handles templating and sending email message
146145
"""
146+
147147
if context is None:
148148
context = {}
149149
context['uri'] = '{scheme}://{host}'.format(
150150
scheme='https', host=settings.PRODUCTION_DOMAIN)
151+
152+
from ..tasks import send_email_task
151153
send_email_task.delay(recipient=recipient, subject=subject, template=template,
152154
template_html=template_html, context=context, from_email=from_email,
153155
**kwargs)

readthedocs/worker.py

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# -*- coding: utf-8 -*-
12
"""Celery worker application instantiation"""
23

34
from __future__ import absolute_import, unicode_literals
@@ -6,14 +7,26 @@
67

78
from celery import Celery
89

10+
from readthedocs.core.utils.extend import SettingsOverrideObject
911

10-
def create_application():
11-
"""Create a Celery application using Django settings"""
12-
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'readthedocs.settings.dev')
13-
application = Celery('readthedocs')
14-
application.config_from_object('django.conf:settings')
15-
application.autodiscover_tasks(None)
16-
return application
1712

13+
class CeleryAppBase(object):
1814

19-
app = create_application() # pylint: disable=invalid-name
15+
def create(self):
16+
"""Create a Celery application using Django settings"""
17+
os.environ.setdefault(
18+
'DJANGO_SETTINGS_MODULE',
19+
'readthedocs.settings.dev',
20+
)
21+
22+
application = Celery('readthedocs')
23+
application.config_from_object('django.conf:settings')
24+
application.autodiscover_tasks(None)
25+
return application
26+
27+
28+
class CeleryApp(SettingsOverrideObject):
29+
_default_class = CeleryAppBase
30+
31+
32+
app = CeleryApp().create()

0 commit comments

Comments
 (0)