Skip to content

Commit da56a7d

Browse files
humitosagjohnson
authored andcommitted
Task to remove orphan symlinks (#3543)
* Use a better db query to accomplish this task * Setup task to be ran by celery beat * Task to remove orphan symlinks * Broadcast the task remove_orphan_symlinks * args attribute is mandatory in broadcast * Fix test
1 parent b242b41 commit da56a7d

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

readthedocs/projects/tasks.py

+10
Original file line numberDiff line numberDiff line change
@@ -828,6 +828,16 @@ def remove_orphan_symlinks():
828828
os.unlink(orphan_domain_path)
829829

830830

831+
@app.task(queue='web')
832+
def broadcast_remove_orphan_symlinks():
833+
"""
834+
Broadcast the task ``remove_orphan_symlinks`` to all our web servers.
835+
836+
This task is executed by CELERY BEAT.
837+
"""
838+
broadcast(type='web', task=remove_orphan_symlinks, args=[])
839+
840+
831841
@app.task(queue='web')
832842
def symlink_subproject(project_pk):
833843
project = Project.objects.get(pk=project_pk)

readthedocs/rtd_tests/tests/test_project_symlinks.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
from readthedocs.builds.models import Version
1616
from readthedocs.projects.models import Project, Domain
17-
from readthedocs.projects.tasks import symlink_project, remove_orphan_symlinks
17+
from readthedocs.projects.tasks import broadcast_remove_orphan_symlinks, remove_orphan_symlinks, symlink_project
1818
from readthedocs.core.symlink import PublicSymlink, PrivateSymlink
1919

2020

@@ -238,6 +238,16 @@ def test_symlink_remove_orphan_symlinks(self):
238238

239239
self.assertFilesystem(filesystem)
240240

241+
def test_broadcast_remove_orphan_symlinks(self):
242+
"""Broadcast orphan symlinks is called with the proper attributes."""
243+
with mock.patch('readthedocs.projects.tasks.broadcast') as broadcast:
244+
broadcast_remove_orphan_symlinks()
245+
246+
broadcast.assert_called_with(
247+
type='web',
248+
task=remove_orphan_symlinks,
249+
args=[],
250+
)
241251

242252
def test_symlink_cname_dont_link_missing_domains(self):
243253
"""Domains should be relinked after deletion"""

readthedocs/settings/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ def USE_PROMOS(self): # noqa
247247
CELERYBEAT_SCHEDULE = {
248248
# Ran every hour on minute 30
249249
'hourly-remove-orphan-symlinks': {
250-
'task': 'readthedocs.projects.tasks.remove_orphan_symlinks',
250+
'task': 'readthedocs.projects.tasks.broadcast_remove_orphan_symlinks',
251251
'schedule': crontab(minute=30),
252252
'options': {'queue': 'web'},
253253
},

0 commit comments

Comments
 (0)