Skip to content

Commit 7792671

Browse files
committed
Allow to hook the initial build from outside
Add a new attribute to `trigger_build` to do not execute the task but just return the immutable signature of it, so it can be chained into a bigger task from outside when it's needed to do something else before/after it's execution.
1 parent a1ef0bb commit 7792671

File tree

4 files changed

+20
-6
lines changed

4 files changed

+20
-6
lines changed

readthedocs/core/utils/__init__.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def cname_to_slug(host):
7575
return slug
7676

7777

78-
def trigger_build(project, version=None, record=True, force=False, basic=False):
78+
def trigger_build(project, version=None, record=True, force=False, basic=False, execute_task=True):
7979
"""
8080
Trigger build for project and version.
8181
@@ -127,10 +127,12 @@ def trigger_build(project, version=None, record=True, force=False, basic=False):
127127
options['soft_time_limit'] = time_limit
128128
options['time_limit'] = int(time_limit * 1.2)
129129

130-
update_docs = UpdateDocsTask()
131-
update_docs.apply_async(kwargs=kwargs, **options)
132-
133-
return build
130+
if not execute_task:
131+
return UpdateDocsTask().si(**kwargs, options=options)
132+
else:
133+
update_docs = UpdateDocsTask()
134+
update_docs.apply_async(kwargs=kwargs, **options)
135+
return build
134136

135137

136138
def send_email(recipient, subject, template, template_html, context=None,

readthedocs/projects/signals.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import django.dispatch
55
from django.dispatch import receiver
66

7+
from readthedocs.core.utils import trigger_build
78
from readthedocs.oauth.utils import attach_webhook
89

910

@@ -23,3 +24,10 @@ def handle_project_import(sender, **kwargs):
2324
request = kwargs.get('request')
2425

2526
attach_webhook(project=project, request=request)
27+
28+
29+
# TODO: move this to ImportWizardView.trigger_initial_build
30+
# @receiver(project_import)
31+
# def trigger_initial_build(sender, request, **kwargs):
32+
# project = sender
33+
# trigger_build(project)

readthedocs/projects/views/private.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,11 @@ def done(self, form_list, **kwargs):
253253
setattr(project, field, value)
254254
basic_only = True
255255
project.save()
256+
257+
# TODO: if we want to make the ``attach_webhook`` async, we need to
258+
# consider the message shown to the user when not valid webhook.
259+
256260
project_import.send(sender=project, request=self.request)
257-
trigger_build(project, basic=basic_only)
258261
return HttpResponseRedirect(
259262
reverse('projects_detail', args=[project.slug]))
260263

readthedocs/settings/dev.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def DATABASES(self): # noqa
3535
CELERY_RESULT_BACKEND = 'redis://localhost:6379/0'
3636
CELERY_RESULT_SERIALIZER = 'json'
3737
CELERY_ALWAYS_EAGER = True
38+
CELERY_TASK_IGNORE_RESULT = False
3839

3940
HAYSTACK_CONNECTIONS = {
4041
'default': {

0 commit comments

Comments
 (0)