diff --git a/readthedocs/projects/tasks.py b/readthedocs/projects/tasks.py index 617a7b4a3ed..4eec679380b 100644 --- a/readthedocs/projects/tasks.py +++ b/readthedocs/projects/tasks.py @@ -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) diff --git a/readthedocs/rtd_tests/tests/test_project_symlinks.py b/readthedocs/rtd_tests/tests/test_project_symlinks.py index ea31c431382..9a1cc99aa0e 100644 --- a/readthedocs/rtd_tests/tests/test_project_symlinks.py +++ b/readthedocs/rtd_tests/tests/test_project_symlinks.py @@ -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 @@ -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""" diff --git a/readthedocs/settings/base.py b/readthedocs/settings/base.py index 36cbe543713..e0c1b933d84 100644 --- a/readthedocs/settings/base.py +++ b/readthedocs/settings/base.py @@ -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'}, },