diff --git a/readthedocs/builds/migrations/0038_track_task_id.py b/readthedocs/builds/migrations/0041_track_task_id.py similarity index 88% rename from readthedocs/builds/migrations/0038_track_task_id.py rename to readthedocs/builds/migrations/0041_track_task_id.py index 411b656dc89..e7bcd23143c 100644 --- a/readthedocs/builds/migrations/0038_track_task_id.py +++ b/readthedocs/builds/migrations/0041_track_task_id.py @@ -6,7 +6,7 @@ class Migration(migrations.Migration): dependencies = [ - ('builds', '0037_alter_build_cold_storage'), + ('builds', '0040_remove_old_jsonfields'), ] operations = [ diff --git a/readthedocs/builds/views.py b/readthedocs/builds/views.py index 50a826ed89b..69d6b9407f0 100644 --- a/readthedocs/builds/views.py +++ b/readthedocs/builds/views.py @@ -16,17 +16,14 @@ from django.views.generic import DetailView, ListView from requests.utils import quote +from readthedocs.builds.constants import BUILD_STATE_TRIGGERED, BUILD_STATE_FINISHED from readthedocs.builds.filters import BuildListFilter from readthedocs.builds.models import Build, Version from readthedocs.core.permissions import AdminPermission from readthedocs.core.utils import trigger_build -from readthedocs.doc_builder.exceptions import BuildAppError +from readthedocs.doc_builder.exceptions import BuildAppError, BuildCancelled from readthedocs.projects.models import Project - -try: - from readthedocsinc.worker import app -except ImportError: - from readthedocs.worker import app +from readthedocs.worker import app log = structlog.get_logger(__name__) @@ -165,8 +162,23 @@ def post(self, request, project_slug, build_pk): return HttpResponseForbidden() # NOTE: `terminate=True` is required for the child to attend our call - # immediately. Otherwise, it finishes the task. - app.control.revoke(build.task_id, signal=signal.SIGINT, terminate=True) + # immediately when it's running the build. Otherwise, it finishes the + # task. However, to revoke a task that has not started yet, we don't + # need it. + if build.state == BUILD_STATE_TRIGGERED: + # Since the task won't be executed at all, we need to update the + # Build object here. + terminate = False + build.state = BUILD_STATE_FINISHED + build.success = False + build.error = BuildCancelled.message + build.save() + else: + # In this case, we left the update of the Build object to the task + # itself to be executed in the `on_failure` handler. + terminate = True + + app.control.revoke(build.task_id, signal=signal.SIGINT, terminate=terminate) return HttpResponseRedirect( reverse('builds_detail', args=[project.slug, build.pk]), diff --git a/readthedocs/templates/builds/build_detail.html b/readthedocs/templates/builds/build_detail.html index c376d2f0dcd..7b6539118cc 100644 --- a/readthedocs/templates/builds/build_detail.html +++ b/readthedocs/templates/builds/build_detail.html @@ -30,10 +30,12 @@ {% block content %}
+ {% if build.state != "finished" %}
{% csrf_token %}
+ {% endif %}