Skip to content

Commit b74542f

Browse files
committed
Refactor 'trigger_initial_build' to allow calling from other places
1 parent e847890 commit b74542f

File tree

2 files changed

+25
-15
lines changed

2 files changed

+25
-15
lines changed

readthedocs/core/utils/__init__.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import os
66
import re
77

8-
from celery import chord, group
8+
from celery import chord, group, chain
99
from django.conf import settings
1010
from django.utils.functional import keep_lazy
1111
from django.utils.safestring import SafeText, mark_safe
@@ -165,6 +165,27 @@ def trigger_build(project, version=None, record=True, force=False):
165165
return (update_docs_task.apply_async(), build)
166166

167167

168+
def trigger_initial_build(project, user):
169+
"""
170+
Trigger initial build after project is imported.
171+
172+
:param project: project's documentation to be built
173+
:returns: Celery AsyncResult promise
174+
"""
175+
176+
update_docs, build = prepare_build(project)
177+
if (update_docs, build) == (None, None):
178+
return None
179+
180+
from readthedocs.oauth.tasks import attach_webhook
181+
task_promise = chain(
182+
attach_webhook.si(project.pk, user.pk),
183+
update_docs,
184+
)
185+
async_result = task_promise.apply_async()
186+
return async_result
187+
188+
168189
def send_email(
169190
recipient, subject, template, template_html, context=None, request=None,
170191
from_email=None, **kwargs

readthedocs/projects/views/private.py

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import logging
44

55
from allauth.socialaccount.models import SocialAccount
6-
from celery import chain
76
from django.conf import settings
87
from django.contrib import messages
98
from django.contrib.auth.decorators import login_required
@@ -24,9 +23,9 @@
2423
from vanilla import CreateView, DeleteView, DetailView, GenericView, UpdateView
2524

2625
from readthedocs.builds.forms import VersionForm
27-
from readthedocs.builds.models import Build, Version
26+
from readthedocs.builds.models import Version
2827
from readthedocs.core.mixins import ListViewWithForm, LoginRequiredMixin
29-
from readthedocs.core.utils import broadcast, prepare_build, trigger_build
28+
from readthedocs.core.utils import broadcast, trigger_build, trigger_initial_build
3029
from readthedocs.integrations.models import HttpExchange, Integration
3130
from readthedocs.oauth.services import registry
3231
from readthedocs.oauth.tasks import attach_webhook
@@ -272,17 +271,7 @@ def done(self, form_list, **kwargs):
272271
)
273272

274273
def trigger_initial_build(self, project):
275-
"""Trigger initial build."""
276-
update_docs, build = prepare_build(project)
277-
if (update_docs, build) == (None, None):
278-
return None
279-
280-
task_promise = chain(
281-
attach_webhook.si(project.pk, self.request.user.pk),
282-
update_docs,
283-
)
284-
async_result = task_promise.apply_async()
285-
return async_result
274+
return trigger_initial_build(project, self.request.user)
286275

287276
def is_advanced(self):
288277
"""Determine if the user selected the `show advanced` field."""

0 commit comments

Comments
 (0)