Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Route task to proper queue #4553

Merged
merged 2 commits into from Aug 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 6 additions & 7 deletions readthedocs/core/utils/__init__.py
Expand Up @@ -139,13 +139,12 @@ def prepare_build(
options['time_limit'] = int(time_limit * 1.2)

update_docs_task = UpdateDocsTask()

# Py 2.7 doesn't support ``**`` expand syntax twice. We create just one big
# kwargs (including the options) for this and expand it just once.
# return update_docs_task.si(project.pk, **kwargs, **options)
kwargs.update(options)

return update_docs_task.si(project.pk, **kwargs)
return update_docs_task.signature(
(project.pk,),
kwargs=kwargs,
options=options,
immutable=True,
)


def trigger_build(project, version=None, record=True, force=False):
Expand Down
109 changes: 78 additions & 31 deletions readthedocs/rtd_tests/tests/test_core_utils.py
@@ -1,3 +1,4 @@
# -*- coding: utf-8 -*-
"""Test core util functions"""

from __future__ import absolute_import
Expand All @@ -17,62 +18,108 @@ def setUp(self):
self.project = get(Project, container_time_limit=None)
self.version = get(Version, project=self.project)

@mock.patch('readthedocs.projects.tasks.UpdateDocsTask')
def test_trigger_custom_queue(self, update_docs):
"""Use a custom queue when routing the task"""
self.project.build_queue = 'build03'
trigger_build(project=self.project, version=self.version)
kwargs = {
'version_pk': self.version.pk,
'record': True,
'force': False,
'build_pk': mock.ANY,
}
options = {
'queue': 'build03',
'time_limit': 720,
'soft_time_limit': 600,
}
update_docs().signature.assert_has_calls([
mock.call(
(self.project.pk,),
kwargs=kwargs,
options=options,
immutable=True,
),
])
update_docs().signature().apply_async.assert_called()

@mock.patch('readthedocs.projects.tasks.UpdateDocsTask')
def test_trigger_build_time_limit(self, update_docs):
"""Pass of time limit"""
trigger_build(project=self.project, version=self.version)
update_docs().si.assert_has_calls([
kwargs = {
'version_pk': self.version.pk,
'record': True,
'force': False,
'build_pk': mock.ANY,
}
options = {
'queue': mock.ANY,
'time_limit': 720,
'soft_time_limit': 600,
}
update_docs().signature.assert_has_calls([
mock.call(
self.project.pk,
time_limit=720,
soft_time_limit=600,
queue=mock.ANY,
force=False,
record=True,
build_pk=mock.ANY,
version_pk=self.version.id,
(self.project.pk,),
kwargs=kwargs,
options=options,
immutable=True,
),
])
update_docs().si().apply_async.assert_called()
update_docs().signature().apply_async.assert_called()

@mock.patch('readthedocs.projects.tasks.UpdateDocsTask')
def test_trigger_build_invalid_time_limit(self, update_docs):
"""Time limit as string"""
self.project.container_time_limit = '200s'
trigger_build(project=self.project, version=self.version)
update_docs().si.assert_has_calls([
kwargs = {
'version_pk': self.version.pk,
'record': True,
'force': False,
'build_pk': mock.ANY,
}
options = {
'queue': mock.ANY,
'time_limit': 720,
'soft_time_limit': 600,
}
update_docs().signature.assert_has_calls([
mock.call(
self.project.pk,
time_limit=720,
soft_time_limit=600,
queue=mock.ANY,
force=False,
record=True,
build_pk=mock.ANY,
version_pk=self.version.id,
(self.project.pk,),
kwargs=kwargs,
options=options,
immutable=True,
),
])
update_docs().si().apply_async.assert_called()
update_docs().signature().apply_async.assert_called()

@mock.patch('readthedocs.projects.tasks.UpdateDocsTask')
def test_trigger_build_rounded_time_limit(self, update_docs):
"""Time limit should round down"""
self.project.container_time_limit = 3
trigger_build(project=self.project, version=self.version)
update_docs().si.assert_has_calls([
kwargs = {
'version_pk': self.version.pk,
'record': True,
'force': False,
'build_pk': mock.ANY,
}
options = {
'queue': mock.ANY,
'time_limit': 3,
'soft_time_limit': 3,
}
update_docs().signature.assert_has_calls([
mock.call(
self.project.pk,
time_limit=3,
soft_time_limit=3,
queue=mock.ANY,
force=False,
record=True,
build_pk=mock.ANY,
version_pk=self.version.id,
(self.project.pk,),
kwargs=kwargs,
options=options,
immutable=True,
),
])
update_docs().si().apply_async.assert_called()

update_docs().signature().apply_async.assert_called()

def test_slugify(self):
"""Test additional slugify"""
Expand Down