Skip to content

Commit

Permalink
Broadcast the task remove_orphan_symlinks
Browse files Browse the repository at this point in the history
  • Loading branch information
humitos committed Mar 22, 2018
1 parent 914ffd5 commit b847b4b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
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)


@app.task(queue='web')
def symlink_subproject(project_pk):
project = Project.objects.get(pk=project_pk)
Expand Down
11 changes: 10 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 remove_orphan_symlinks, symlink_project
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,15 @@ 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,
)

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

0 comments on commit b847b4b

Please sign in to comment.