Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions readthedocs/projects/tasks/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,10 @@ def finish_unhealthy_builds():
builds_finished = []
builds = Build.objects.filter(query)[:50]
for build in builds:
if build.commands.exists():
# Try to update the build length if there is at least one command
build.length = (timezone.now() - build.commands.first().start_time).seconds

build.success = False
build.state = BUILD_STATE_CANCELLED
build.save()
Expand Down
5 changes: 4 additions & 1 deletion readthedocs/rtd_tests/tests/test_projects_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
BUILD_STATE_TRIGGERED,
EXTERNAL,
)
from readthedocs.builds.models import Build, Version
from readthedocs.builds.models import Build, BuildCommandResult, Version
from readthedocs.projects.models import Feature, Project
from readthedocs.projects.tasks.utils import finish_unhealthy_builds, send_external_build_status

Expand Down Expand Up @@ -93,6 +93,8 @@ def test_finish_unhealthy_builds_task(self, mocked_app):
healthcheck=timezone.now() - datetime.timedelta(minutes=15),
)

get(BuildCommandResult, build=build_3, start_time=timezone.now())

finish_unhealthy_builds()

build_1.refresh_from_db()
Expand All @@ -103,5 +105,6 @@ def test_finish_unhealthy_builds_task(self, mocked_app):

build_3.refresh_from_db()
self.assertEqual(build_3.state, BUILD_STATE_CANCELLED)
self.assertIsNotNone(build_3.length)
self.assertEqual(build_3.success, False)
self.assertEqual(build_3.notifications.count(), 1)