Skip to content

Build process: use Celery handlers #8815

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

Merged
merged 98 commits into from
Feb 7, 2022
Merged
Show file tree
Hide file tree
Changes from 92 commits
Commits
Show all changes
98 commits
Select commit Hold shift + click to select a range
3b758a6
Build process: use Celery handlers
humitos Jan 13, 2022
b7e4683
Build process: more updates and cleanup
humitos Jan 17, 2022
61b5e8b
Test: fix import issues for functions moved
humitos Jan 17, 2022
0f8cc23
Test: LocalBuildEnvironment run(), __enter__ and __exit__ required
humitos Jan 17, 2022
f80d2c7
Test: remove tests for deleted "features"
humitos Jan 17, 2022
d3f0dde
Test: comment about not passing environment when required
humitos Jan 17, 2022
f1c960b
Build: add `self.environment_class` variable to sync_repository_task
humitos Jan 17, 2022
c72f02c
Test: more import moves
humitos Jan 17, 2022
bc8c4e8
Test: avoid short-circuiting the task to test
humitos Jan 17, 2022
2c07948
Cleanup: remove "Wipe" feature
humitos Jan 17, 2022
a5123cc
Test: mock fixes and import paths
humitos Jan 17, 2022
640b3d3
Cleanup: remove pip cache method helper
humitos Jan 17, 2022
8df55fd
Test: comments and notes about what how to migrate them
humitos Jan 17, 2022
a6053d9
Cleanup: remove outdated things
humitos Jan 18, 2022
7b382dc
clean_build: pass the version object
humitos Jan 18, 2022
4f3e213
Test: migrate `rtd_tests/test_builds.py` to new format
humitos Jan 18, 2022
38a005a
Build: re-organize files
humitos Jan 19, 2022
5abb5a7
Build: the reference to the task is just `self`
humitos Jan 19, 2022
fdd884d
Build: follow the same pattern for localmedia than the others
humitos Jan 19, 2022
4eaab60
Typo: remove comma (,) from logging line to match the rest
humitos Jan 19, 2022
354da75
Test: initial structure to mock the build completely
humitos Jan 19, 2022
65d9d04
Test: call the task with `.delay`
humitos Jan 19, 2022
d3e0bb7
Test: check important calls when the build fails
humitos Jan 19, 2022
535834b
Cleanup: small fixes and comments
humitos Jan 19, 2022
d49ef65
Test: full test for successful build
humitos Jan 19, 2022
2fba199
Test: migrate/update build tests
humitos Jan 19, 2022
2263a53
Test: ignore errors when cleaning up test environment
humitos Jan 19, 2022
99ad8c1
Test: removed hardcoded path to avoid CircleCI failing
humitos Jan 19, 2022
a359fd6
Test: commend and delete invalid/non-useful tests
humitos Jan 20, 2022
b7feb4d
Test: more tests migrated
humitos Jan 20, 2022
0bf8171
Test: mkdocs fail on warning migrated
humitos Jan 20, 2022
03e8bc2
Test: migrate sphinx fail on warning
humitos Jan 20, 2022
1273a68
Test: --system-site-packages test migrated
humitos Jan 20, 2022
5e94afb
Test: tearDown for mock.stop()
humitos Jan 20, 2022
3311bc3
Test: migrate tests for config file and commands executed
humitos Jan 20, 2022
9841b2a
Test: make usage of pytest features to avoid repetition
humitos Jan 20, 2022
cb74e02
Test: config file submodule tests migrated
humitos Jan 20, 2022
503d10e
Test: refactor classes to share more code
humitos Jan 20, 2022
e77bd40
Test: migrate test to check sphinx builder in config file
humitos Jan 20, 2022
d2d6f8a
Test: update some tests to use ConfigV2
humitos Jan 21, 2022
2e11886
Build: remove the concept of "forcing a build"
humitos Jan 21, 2022
41c4f2f
Build: remove the ability to (not)record a whole Build object
humitos Jan 21, 2022
a4b1d70
Test: adapt test to not check `force` and `record` anymore
humitos Jan 21, 2022
0cc8a73
Build: remove BuildEnvironmentWarning exception
humitos Jan 21, 2022
41a6d1e
Build: make sure we have `self.build_pk` when handling exceptions
humitos Jan 21, 2022
a45c703
Build: `build` is mandatory when when "triggering a build"
humitos Jan 21, 2022
4742600
Cleanup: remove unused helper function
humitos Jan 21, 2022
f6100be
Build: differentiate "user errors" from "app errors"
humitos Jan 21, 2022
a5c8cc9
Cleanup: remove `BuildCommand.description`
humitos Jan 21, 2022
0ca908e
Build: generic message for OOM/timeout when `Killed` in output
humitos Jan 21, 2022
5d41fed
Build: save 'builder' when its known
humitos Jan 24, 2022
6299525
Logging: log build has finished + length and success)
humitos Jan 24, 2022
00861bc
Test: remove more unused/invalid tests
humitos Jan 24, 2022
6426900
Test: install pdbpp for debugging
humitos Jan 24, 2022
ce306aa
Test: improve test for multiple formats
humitos Jan 24, 2022
1c2eb6a
Cleanup: remove debugging stuffs
humitos Jan 24, 2022
92e701b
Build: set "Installing" state when running apt-get
humitos Jan 24, 2022
40c373c
Docs: update/organize docstring a little more
humitos Jan 24, 2022
2f6d89b
VCS support: normalize error reporting
humitos Jan 24, 2022
a530ad9
Test: fix message reported to user
humitos Jan 24, 2022
9e017c9
Test: do not check specific `cwd=` in commands
humitos Jan 24, 2022
ceb3dcc
Merge branch 'master' of github.com:readthedocs/readthedocs.org into …
humitos Jan 24, 2022
4f06286
Docs: add todo comment
humitos Jan 24, 2022
aba7b1e
Celery beat: change path for periodic task
humitos Jan 24, 2022
d5a8ffb
Deploy: re-define the task under `readthedocs.projects.tasks`
humitos Jan 24, 2022
48c3507
Build: remove version locking
humitos Jan 26, 2022
91a2e9a
Cleanup: remove methods not used from Environment
humitos Jan 26, 2022
d0a22e2
Cleanup: remove setting `Build` fields that are not used
humitos Jan 26, 2022
d27e487
Build: improve copy for user facing error messages
humitos Jan 26, 2022
a393ddb
Celery: re-register new task names under old names
humitos Jan 26, 2022
0f8af38
Merge branch 'humitos/celery-handlers' of github.com:readthedocs/read…
humitos Jan 26, 2022
b3d7491
Celery: add more renamed tasks
humitos Jan 26, 2022
9fff24f
Celery: make required arguments mandatory for build tasks
humitos Jan 26, 2022
ac24233
Build: use BuildAppError instead BuildEnvironmentError
humitos Jan 26, 2022
928cabf
Test: translate checks for duplicated versions
humitos Jan 26, 2022
f48abbd
Test: cleanup old tests
humitos Jan 26, 2022
fb27227
Build: rename tasks in router
humitos Jan 26, 2022
d35d5c8
Test: cleanup and remove `EnvironmentMockGroup` old class
humitos Jan 26, 2022
a3bc857
Build: fix usage of `self.build_commit` to do the VCS checkout
humitos Jan 26, 2022
41216c8
Test: cleanup them a migrate one more
humitos Jan 26, 2022
99c704d
Test: meh, this is required even if we don't use Docker for tests
humitos Jan 26, 2022
7534a84
Lint and leftovers: delete old comments/code and fix linting
humitos Jan 26, 2022
40a7750
CircleCI: give more memory to elasticsearch
humitos Jan 26, 2022
21c3f10
Merge branch 'master' of github.com:readthedocs/readthedocs.org into …
humitos Jan 26, 2022
68f257f
Docs: delete wipe docs
humitos Jan 26, 2022
9154e8d
Celery: re-register tasks with the old name
humitos Jan 26, 2022
1e9c724
Celery: update old tasks to behave correctly
humitos Jan 26, 2022
8b237a3
Lint: undefined variable
humitos Feb 1, 2022
174985a
Celery: use an internal namespace to store build task's data
humitos Feb 1, 2022
699fe96
Merge branch 'master' of github.com:readthedocs/readthedocs.org into …
humitos Feb 3, 2022
e08c00e
Merge branch 'humitos/celery-handlers' of github.com:readthedocs/read…
humitos Feb 3, 2022
017df68
Lint
humitos Feb 3, 2022
a546f59
Test: check for pinned version of pip
humitos Feb 3, 2022
4c89df1
Lint
humitos Feb 3, 2022
fde6a1a
Merge branch 'master' of github.com:readthedocs/readthedocs.org into …
humitos Feb 7, 2022
f8ab09e
Re-structure: move search utils tasks into `...tasks.search`
humitos Feb 7, 2022
2491854
Merge branch 'humitos/celery-handlers' of github.com:readthedocs/read…
humitos Feb 7, 2022
b68730d
Merge pull request #8874 from readthedocs/humitos/celery-handlers-self
humitos Feb 7, 2022
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
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ jobs:
name: search
environment:
discovery.type: single-node
ES_JAVA_OPTS: -Xms750m -Xmx750m
steps:
- checkout
- run: git submodule sync
Expand Down
6 changes: 0 additions & 6 deletions docs/user/faq.rst
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,6 @@ following settings::
SLUMBER_PASSWORD = 'test'


Deleting a stale or broken build environment
--------------------------------------------

See :doc:`guides/wipe-environment`.


How do I host multiple projects on one custom domain?
-----------------------------------------------------

Expand Down
1 change: 0 additions & 1 deletion docs/user/guides/administrators.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,3 @@ have a look at our :doc:`/tutorial/index`.
deprecating-content
pdf-non-ascii-languages
importing-private-repositories
wipe-environment
28 changes: 0 additions & 28 deletions docs/user/guides/wipe-environment.rst

This file was deleted.

2 changes: 1 addition & 1 deletion readthedocs/api/v3/tests/test_builds.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from .mixins import APIEndpointMixin


@mock.patch('readthedocs.projects.tasks.update_docs_task', mock.MagicMock())
@mock.patch('readthedocs.projects.tasks.builds.update_docs_task', mock.MagicMock())
class BuildsEndpointTests(APIEndpointMixin):

def test_projects_builds_list(self):
Expand Down
2 changes: 1 addition & 1 deletion readthedocs/api/v3/tests/test_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from .mixins import APIEndpointMixin


@mock.patch('readthedocs.projects.tasks.update_docs_task', mock.MagicMock())
@mock.patch('readthedocs.projects.tasks.builds.update_docs_task', mock.MagicMock())
class ProjectsEndpointTests(APIEndpointMixin):

def test_projects_list(self):
Expand Down
21 changes: 3 additions & 18 deletions readthedocs/builds/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
VersionAutomationRule,
)
from readthedocs.core.utils import trigger_build
from readthedocs.core.utils.general import wipe_version_via_slugs
from readthedocs.projects.models import HTMLFile
from readthedocs.search.utils import _indexing_helper

Expand Down Expand Up @@ -118,29 +117,15 @@ class VersionAdmin(admin.ModelAdmin):
list_filter = ('type', 'privacy_level', 'active', 'built')
search_fields = ('slug', 'project__slug')
raw_id_fields = ('project',)
actions = ['build_version', 'reindex_version', 'wipe_version', 'wipe_selected_versions']
actions = ['build_version', 'reindex_version', 'wipe_version_indexes']

def project_slug(self, obj):
return obj.project.slug

def wipe_selected_versions(self, request, queryset):
"""Wipes the selected versions."""
for version in queryset:
wipe_version_via_slugs(
version_slug=version.slug,
project_slug=version.project.slug
)
self.message_user(
request,
'Wiped {}.'.format(version.slug),
level=messages.SUCCESS
)

def pretty_config(self, instance):
return _pretty_config(instance)

pretty_config.short_description = 'Config File'
wipe_selected_versions.short_description = 'Wipe selected versions'

def build_version(self, request, queryset):
"""Trigger a build for the project version."""
Expand Down Expand Up @@ -179,7 +164,7 @@ def reindex_version(self, request, queryset):

reindex_version.short_description = 'Reindex version to ES'

def wipe_version(self, request, queryset):
def wipe_version_indexes(self, request, queryset):
"""Wipe selected versions from ES."""
html_objs_qs = []
for version in queryset.iterator():
Expand All @@ -197,7 +182,7 @@ def wipe_version(self, request, queryset):
messages.SUCCESS,
)

wipe_version.short_description = 'Wipe version from ES'
wipe_version_indexes.short_description = 'Wipe version from ES'


@admin.register(RegexAutomationRule)
Expand Down
7 changes: 5 additions & 2 deletions readthedocs/builds/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,9 @@ def get_absolute_url(self):
)

def delete(self, *args, **kwargs): # pylint: disable=arguments-differ
from readthedocs.projects import tasks
from readthedocs.projects.tasks.utils import clean_project_resources
log.info('Removing files for version.', version_slug=self.slug)
tasks.clean_project_resources(self.project, self)
clean_project_resources(self.project, self)
super().delete(*args, **kwargs)

@property
Expand Down Expand Up @@ -614,6 +614,9 @@ class Build(models.Model):
date = models.DateTimeField(_('Date'), auto_now_add=True, db_index=True)
success = models.BooleanField(_('Success'), default=True)

# TODO: remove these fields (setup, setup_error, output, error, exit_code)
# since they are not used anymore in the new implementation and only really
# old builds (>5 years ago) only were using these fields.
setup = models.TextField(_('Setup'), null=True, blank=True)
setup_error = models.TextField(_('Setup error'), null=True, blank=True)
output = models.TextField(_('Output'), default='', blank=True)
Expand Down
8 changes: 4 additions & 4 deletions readthedocs/builds/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ class TaskRouter:
def route_for_task(self, task, args, kwargs, **__):
log.debug('Executing TaskRouter.', task=task)
if task not in (
'readthedocs.projects.tasks.update_docs_task',
'readthedocs.projects.tasks.sync_repository_task',
'readthedocs.projects.tasks.builds.update_docs_task',
'readthedocs.projects.tasks.builds.sync_repository_task',
):
log.debug('Skipping routing non-build task.', task=task)
return
Expand Down Expand Up @@ -153,8 +153,8 @@ def route_for_task(self, task, args, kwargs, **__):

def _get_version(self, task, args, kwargs):
tasks = [
'readthedocs.projects.tasks.update_docs_task',
'readthedocs.projects.tasks.sync_repository_task',
'readthedocs.projects.tasks.builds.update_docs_task',
'readthedocs.projects.tasks.builds.sync_repository_task',
]
version = None
if task in tasks:
Expand Down
2 changes: 1 addition & 1 deletion readthedocs/builds/tests/test_celery_task_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def setUp(self):

)

self.task = 'readthedocs.projects.tasks.update_docs_task'
self.task = 'readthedocs.projects.tasks.builds.update_docs_task'
self.args = (
self.version.pk,
)
Expand Down
4 changes: 2 additions & 2 deletions readthedocs/builds/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from readthedocs.builds.models import Build, Version
from readthedocs.core.permissions import AdminPermission
from readthedocs.core.utils import trigger_build
from readthedocs.doc_builder.exceptions import BuildEnvironmentError
from readthedocs.doc_builder.exceptions import BuildAppError
from readthedocs.projects.models import Project

log = structlog.get_logger(__name__)
Expand Down Expand Up @@ -154,7 +154,7 @@ def get_context_data(self, **kwargs):

build = self.get_object()

if build.error != BuildEnvironmentError.GENERIC_WITH_BUILD_ID.format(build_id=build.pk):
if build.error != BuildAppError.GENERIC_WITH_BUILD_ID.format(build_id=build.pk):
# Do not suggest to open an issue if the error is not generic
return context

Expand Down
1 change: 1 addition & 0 deletions readthedocs/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
LATEST_CONFIGURATION_VERSION = 2


# TODO: make these exception to inherit from `BuildUserError`
class ConfigError(Exception):

"""Base error for the rtd configuration file."""
Expand Down
11 changes: 1 addition & 10 deletions readthedocs/core/management/commands/update_repos.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,6 @@ class Command(BaseCommand):
def add_arguments(self, parser):
parser.add_argument('--slugs', nargs='+', type=str)

parser.add_argument(
'-f',
action='store_true',
dest='force',
default=False,
help='Force a build in sphinx',
)

parser.add_argument(
'-V',
dest='version',
Expand All @@ -41,7 +33,6 @@ def add_arguments(self, parser):
)

def handle(self, *args, **options):
force = options['force']
version = options['version']
slugs = options.get('slugs', [])

Expand Down Expand Up @@ -85,7 +76,7 @@ def handle(self, *args, **options):
else:
p = Project.all_objects.get(slug=slug)
log.info('Building ...', project_slug=p.slug)
trigger_build(project=p, force=force)
trigger_build(project=p)
else:
if version == 'all':
log.info('Updating all versions')
Expand Down
3 changes: 3 additions & 0 deletions readthedocs/core/tests/test_history.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from unittest import mock

from django.contrib.auth.models import User
from django.test import TestCase
from django.urls import reverse
Expand All @@ -13,6 +15,7 @@ def setUp(self):
self.project = get(Project, users=[self.user])
self.client.force_login(self.user)

@mock.patch('readthedocs.projects.forms.trigger_build', mock.MagicMock())
def test_extra_historical_fields_with_request(self):
self.assertEqual(self.project.history.count(), 1)
r = self.client.post(
Expand Down
20 changes: 0 additions & 20 deletions readthedocs/core/urls/__init__.py

This file was deleted.

Loading