diff --git a/readthedocs/projects/tasks/utils.py b/readthedocs/projects/tasks/utils.py index 8de3c4d8f4e..e318b34466d 100644 --- a/readthedocs/projects/tasks/utils.py +++ b/readthedocs/projects/tasks/utils.py @@ -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() diff --git a/readthedocs/rtd_tests/tests/test_projects_tasks.py b/readthedocs/rtd_tests/tests/test_projects_tasks.py index a21b2030426..08d654a5b0e 100644 --- a/readthedocs/rtd_tests/tests/test_projects_tasks.py +++ b/readthedocs/rtd_tests/tests/test_projects_tasks.py @@ -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 @@ -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() @@ -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)