Skip to content

Task to remove orphan symlinks #3543

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 7 commits into from
Mar 23, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions readthedocs/projects/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -828,6 +828,16 @@ def remove_orphan_symlinks():
os.unlink(orphan_domain_path)


@app.task(queue='web')
def broadcast_remove_orphan_symlinks():
"""
Broadcast the task ``remove_orphan_symlinks`` to all our web servers.

This task is executed by CELERY BEAT.
"""
broadcast(type='web', task=remove_orphan_symlinks, args=[])


@app.task(queue='web')
def symlink_subproject(project_pk):
project = Project.objects.get(pk=project_pk)
Expand Down
12 changes: 11 additions & 1 deletion readthedocs/rtd_tests/tests/test_project_symlinks.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from readthedocs.builds.models import Version
from readthedocs.projects.models import Project, Domain
from readthedocs.projects.tasks import symlink_project, remove_orphan_symlinks
from readthedocs.projects.tasks import broadcast_remove_orphan_symlinks, remove_orphan_symlinks, symlink_project
from readthedocs.core.symlink import PublicSymlink, PrivateSymlink


Expand Down Expand Up @@ -238,6 +238,16 @@ def test_symlink_remove_orphan_symlinks(self):

self.assertFilesystem(filesystem)

def test_broadcast_remove_orphan_symlinks(self):
"""Broadcast orphan symlinks is called with the proper attributes."""
with mock.patch('readthedocs.projects.tasks.broadcast') as broadcast:
broadcast_remove_orphan_symlinks()

broadcast.assert_called_with(
type='web',
task=remove_orphan_symlinks,
args=[],
)

def test_symlink_cname_dont_link_missing_domains(self):
"""Domains should be relinked after deletion"""
Expand Down
2 changes: 1 addition & 1 deletion readthedocs/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ def USE_PROMOS(self): # noqa
CELERYBEAT_SCHEDULE = {
# Ran every hour on minute 30
'hourly-remove-orphan-symlinks': {
'task': 'readthedocs.projects.tasks.remove_orphan_symlinks',
'task': 'readthedocs.projects.tasks.broadcast_remove_orphan_symlinks',
'schedule': crontab(minute=30),
'options': {'queue': 'web'},
},
Expand Down