Skip to content

Commit

Permalink
Build: add a new "Cancelled" final state
Browse files Browse the repository at this point in the history
This is just a POC to show some of the work involved in #9100
  • Loading branch information
humitos committed Apr 27, 2022
1 parent 7db6582 commit 124301c
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 23 deletions.
11 changes: 5 additions & 6 deletions media/javascript/build_updater.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
var el = $(this.buildDiv + ' span#build-' + prop);

if (prop == 'success') {
if (data.hasOwnProperty('state') && data['state'] != 'finished') {
if (data.hasOwnProperty('state') && data['state'] != 'finished') && data['state'] != 'cancelled' {
val = "Not yet finished";
}
else {
Expand All @@ -41,7 +41,7 @@
if (prop == 'state') {
val = val.charAt(0).toUpperCase() + val.slice(1);

if (val == 'Finished') {
if (val == 'Finished' || val == 'Cancelled') {
_this.stopPolling();
}
}
Expand All @@ -55,7 +55,7 @@

BuildUpdater.prototype.getBuild = function() {
_this = this;

$.get(this.buildUrl, function(data) {
_this.render(data);
});
Expand All @@ -74,7 +74,7 @@

// If the build is already finished, or it isn't displayed on the page,
// ignore it.
if (stateSpan.text() == 'Finished' || stateSpan.length === 0) {
if (stateSpan.text() == 'Finished' || stateSpan.text() == 'Cancelled' || stateSpan.length === 0) {
return;
}

Expand Down Expand Up @@ -117,7 +117,7 @@
if (prop == 'state') {
// Show the success value ("Passed" or "Failed") if the build
// finished. Otherwise, show the state value.
if (val == 'Finished') {
if (val == 'Finished' || val == 'Cancelled') {
val = data['success'];
_this.stopPolling();
} else {
Expand All @@ -134,4 +134,3 @@


}).call(this);

31 changes: 19 additions & 12 deletions readthedocs/builds/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,27 @@
from django.conf import settings
from django.utils.translation import gettext_lazy as _

BUILD_STATE_TRIGGERED = 'triggered'
BUILD_STATE_CLONING = 'cloning'
BUILD_STATE_INSTALLING = 'installing'
BUILD_STATE_BUILDING = 'building'
BUILD_STATE_UPLOADING = 'uploading'
BUILD_STATE_FINISHED = 'finished'
BUILD_STATE_TRIGGERED = "triggered"
BUILD_STATE_CLONING = "cloning"
BUILD_STATE_INSTALLING = "installing"
BUILD_STATE_BUILDING = "building"
BUILD_STATE_UPLOADING = "uploading"
BUILD_STATE_FINISHED = "finished"
BUILD_STATE_CANCELLED = "cancelled"

BUILD_STATE = (
(BUILD_STATE_TRIGGERED, _('Triggered')),
(BUILD_STATE_CLONING, _('Cloning')),
(BUILD_STATE_INSTALLING, _('Installing')),
(BUILD_STATE_BUILDING, _('Building')),
(BUILD_STATE_UPLOADING, _('Uploading')),
(BUILD_STATE_FINISHED, _('Finished')),
(BUILD_STATE_TRIGGERED, _("Triggered")),
(BUILD_STATE_CLONING, _("Cloning")),
(BUILD_STATE_INSTALLING, _("Installing")),
(BUILD_STATE_BUILDING, _("Building")),
(BUILD_STATE_UPLOADING, _("Uploading")),
(BUILD_STATE_FINISHED, _("Finished")),
(BUILD_STATE_CANCELLED, _("Cancelled")),
)

BUILD_FINAL_STATES = (
BUILD_STATE_FINISHED,
BUILD_STATE_CANCELLED,
)

BUILD_TYPES = (
Expand Down
3 changes: 2 additions & 1 deletion readthedocs/core/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from django.utils.text import slugify as slugify_base

from readthedocs.builds.constants import (
BUILD_STATE_CANCELLED,
BUILD_STATE_FINISHED,
BUILD_STATE_TRIGGERED,
BUILD_STATUS_PENDING,
Expand Down Expand Up @@ -161,7 +162,7 @@ def prepare_build(
build.status = DuplicatedBuildError.status
build.exit_code = DuplicatedBuildError.exit_code
build.success = False
build.state = BUILD_STATE_FINISHED
build.state = BUILD_STATE_CANCELLED
build.save()

# Start the build in X minutes and mark it as limited
Expand Down
12 changes: 9 additions & 3 deletions readthedocs/projects/tasks/builds.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from readthedocs.api.v2.client import api as api_v2
from readthedocs.builds import tasks as build_tasks
from readthedocs.builds.constants import (
BUILD_FINAL_STATES,
BUILD_STATE_BUILDING,
BUILD_STATE_CLONING,
BUILD_STATE_FINISHED,
Expand Down Expand Up @@ -539,7 +540,11 @@ def after_return(self, status, retval, task_id, args, kwargs, einfo):
# Update build object
self.data.build['length'] = (timezone.now() - self.data.start_time).seconds

self.update_build(BUILD_STATE_FINISHED)
build_state = None
if self.build["state"] not in BUILD_FINAL_STATES:
build_state = BUILD_STATE_FINISHED

self.update_build(build_state)

build_complete.send(sender=Build, build=self.data.build)

Expand All @@ -551,8 +556,9 @@ def after_return(self, status, retval, task_id, args, kwargs, einfo):
success=self.data.build['success']
)

def update_build(self, state):
self.data.build['state'] = state
def update_build(self, state=None):
if state:
self.data.build["state"] = state

# Attempt to stop unicode errors on build reporting
# for key, val in list(self.data.build.items()):
Expand Down
2 changes: 1 addition & 1 deletion readthedocs/templates/builds/build_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
{% block content %}
<div class="build build-detail" id="build-detail">

{% if build.state != "finished" and request.user|is_admin:project %}
{% if build.state != "finished" and build.state != "cancelled" and request.user|is_admin:project %}
<form method="post" action="{% url "builds_detail" build.version.project.slug build.pk %}">
{% csrf_token %}
<input type="submit" value="{% trans "Cancel build" %}">
Expand Down

0 comments on commit 124301c

Please sign in to comment.