|
1 | 1 | """Views for builds app."""
|
2 | 2 |
|
3 |
| -import signal |
4 | 3 | import textwrap
|
5 | 4 | from urllib.parse import urlparse
|
6 | 5 |
|
|
23 | 22 | from readthedocs.builds.filters import BuildListFilter
|
24 | 23 | from readthedocs.builds.models import Build, Version
|
25 | 24 | from readthedocs.core.permissions import AdminPermission
|
26 |
| -from readthedocs.core.utils import trigger_build |
27 |
| -from readthedocs.doc_builder.exceptions import BuildAppError, BuildCancelled |
| 25 | +from readthedocs.core.utils import cancel_build, trigger_build |
| 26 | +from readthedocs.doc_builder.exceptions import BuildAppError |
28 | 27 | from readthedocs.projects.models import Project
|
29 |
| -from readthedocs.worker import app |
30 | 28 |
|
31 | 29 | log = structlog.get_logger(__name__)
|
32 | 30 |
|
@@ -167,33 +165,7 @@ def post(self, request, project_slug, build_pk):
|
167 | 165 | if not AdminPermission.is_admin(request.user, project):
|
168 | 166 | return HttpResponseForbidden()
|
169 | 167 |
|
170 |
| - # NOTE: `terminate=True` is required for the child to attend our call |
171 |
| - # immediately when it's running the build. Otherwise, it finishes the |
172 |
| - # task. However, to revoke a task that has not started yet, we don't |
173 |
| - # need it. |
174 |
| - if build.state == BUILD_STATE_TRIGGERED: |
175 |
| - # Since the task won't be executed at all, we need to update the |
176 |
| - # Build object here. |
177 |
| - terminate = False |
178 |
| - build.state = BUILD_STATE_CANCELLED |
179 |
| - build.success = False |
180 |
| - build.error = BuildCancelled.message |
181 |
| - build.length = 0 |
182 |
| - build.save() |
183 |
| - else: |
184 |
| - # In this case, we left the update of the Build object to the task |
185 |
| - # itself to be executed in the `on_failure` handler. |
186 |
| - terminate = True |
187 |
| - |
188 |
| - log.warning( |
189 |
| - 'Canceling build.', |
190 |
| - project_slug=project.slug, |
191 |
| - version_slug=build.version.slug, |
192 |
| - build_id=build.pk, |
193 |
| - build_task_id=build.task_id, |
194 |
| - terminate=terminate, |
195 |
| - ) |
196 |
| - app.control.revoke(build.task_id, signal=signal.SIGINT, terminate=terminate) |
| 168 | + cancel_build(build) |
197 | 169 |
|
198 | 170 | return HttpResponseRedirect(
|
199 | 171 | reverse('builds_detail', args=[project.slug, build.pk]),
|
|
0 commit comments