Skip to content

Commit ca600bc

Browse files
committed
Router PRs builds to last queue where a build was executed
Currently, every time a PR is triggered to be built we are building it under our build:large queue. This is because we have no data about this version and we build them on build:large. This commit checks where the last build was built when a PR is triggered to be built and use that queue to build the PR. Closes #7815
1 parent 7a117b6 commit ca600bc

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

readthedocs/builds/tasks.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
)
1616
from readthedocs.builds.constants import (
1717
BRANCH,
18+
EXTERNAL,
1819
BUILD_STATUS_FAILURE,
1920
BUILD_STATUS_PENDING,
2021
BUILD_STATUS_SUCCESS,
@@ -38,10 +39,11 @@ class TaskRouter:
3839
Celery tasks router.
3940
4041
It allows us to decide which queue is where we want to execute the task
41-
based on project's settings but also in queue availability.
42+
based on project's settings.
4243
4344
1. the project is using conda
4445
2. new project with less than N successful builds
46+
3. version to be built is external
4547
4648
It ignores projects that have already set ``build_queue`` attribute.
4749
@@ -92,6 +94,16 @@ def route_for_task(self, task, args, kwargs, **__):
9294
)
9395
return self.BUILD_LARGE_QUEUE
9496

97+
# Use last queue used for external versions
98+
if version.type == EXTERNAL:
99+
for build in last_builds.iterator():
100+
if not build.builder:
101+
continue
102+
103+
if 'default' in build.builder:
104+
return self.BUILD_DEFAULT_QUEUE
105+
return self.BUILD_LARGE_QUEUE
106+
95107
# We do not have enough builds for this version yet
96108
if queryset.count() < self.N_BUILDS:
97109
log.info(

readthedocs/builds/tests/test_celery_task_router.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from django.test import TestCase
44
from django.test.utils import override_settings
55

6+
from readthedocs.builds.constants import EXTERNAL
67
from readthedocs.builds.models import Build, Version
78
from readthedocs.builds.tasks import TaskRouter
89
from readthedocs.projects.models import Project
@@ -67,3 +68,23 @@ def test_no_build_pk(self):
6768
self.assertIsNone(
6869
self.router.route_for_task(self.task, self.args, {}),
6970
)
71+
72+
def test_external_version(self):
73+
self.version.type = EXTERNAL
74+
self.version.save()
75+
76+
self.build.builder = 'build-default-a1b2c3'
77+
self.build.save()
78+
79+
self.assertEqual(
80+
self.router.route_for_task(self.task, self.args, self.kwargs),
81+
TaskRouter.BUILD_DEFAULT_QUEUE,
82+
)
83+
84+
self.build.builder = 'build-large-a1b2c3'
85+
self.build.save()
86+
87+
self.assertEqual(
88+
self.router.route_for_task(self.task, self.args, self.kwargs),
89+
TaskRouter.BUILD_LARGE_QUEUE,
90+
)

0 commit comments

Comments
 (0)