-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Move move_files to a broadcast model. #2946
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
Changes from 9 commits
4120c38
d55b024
eff0ab2
9827a49
964e09b
7d052ab
90a0033
9b50f41
da38987
318c39a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,7 +32,7 @@ | |
BUILD_STATE_FINISHED) | ||
from readthedocs.builds.models import Build, Version | ||
from readthedocs.builds.signals import build_complete | ||
from readthedocs.core.utils import send_email, run_on_app_servers, broadcast | ||
from readthedocs.core.utils import send_email, broadcast | ||
from readthedocs.core.symlink import PublicSymlink, PrivateSymlink | ||
from readthedocs.cdn.purge import purge | ||
from readthedocs.doc_builder.loader import get_builder_class | ||
|
@@ -395,11 +395,10 @@ def build_docs_html(self): | |
|
||
# Gracefully attempt to move files via task on web workers. | ||
try: | ||
move_files.delay( | ||
version_pk=self.version.pk, | ||
html=True, | ||
hostname=socket.gethostname(), | ||
) | ||
broadcast(type='app', task=move_files, | ||
args=[self.version.pk, socket.gethostname()], | ||
kwargs=dict(html=True) | ||
) | ||
except socket.error: | ||
# TODO do something here | ||
pass | ||
|
@@ -555,25 +554,27 @@ def finish_build(version_pk, build_pk, hostname=None, html=False, | |
version.save() | ||
|
||
if not pdf: | ||
clear_pdf_artifacts(version) | ||
broadcast(type='app', task=clear_pdf_artifacts, args=[version.pk]) | ||
if not epub: | ||
clear_epub_artifacts(version) | ||
|
||
move_files( | ||
version_pk=version_pk, | ||
hostname=hostname, | ||
html=html, | ||
localmedia=localmedia, | ||
search=search, | ||
pdf=pdf, | ||
epub=epub, | ||
) | ||
broadcast(type='app', task=clear_epub_artifacts, args=[version.pk]) | ||
|
||
# Sync files to the web servers | ||
broadcast(type='app', task=move_files, args=[version_pk, hostname], | ||
kwargs=dict( | ||
html=html, | ||
localmedia=localmedia, | ||
search=search, | ||
pdf=pdf, | ||
epub=epub, | ||
)) | ||
|
||
# Symlink project on every web | ||
broadcast(type='app', task=symlink_project, args=[version.project.pk]) | ||
|
||
# Update metadata | ||
broadcast(type='app', task=update_static_metadata, args=[version.project.pk]) | ||
|
||
# Delayed tasks | ||
update_static_metadata.delay(version.project.pk) | ||
fileify.delay(version.pk, commit=build.commit) | ||
update_search.delay(version.pk, commit=build.commit) | ||
|
||
|
@@ -887,7 +888,6 @@ def update_static_metadata(project_pk, path=None): | |
fh = open(path, 'w+') | ||
json.dump(metadata, fh) | ||
fh.close() | ||
Syncer.copy(path, path, host=socket.gethostname(), is_file=True) | ||
except (AttributeError, IOError) as e: | ||
log.debug(LOG_TEMPLATE.format( | ||
project=project.slug, | ||
|
@@ -909,7 +909,7 @@ def remove_dir(path): | |
shutil.rmtree(path, ignore_errors=True) | ||
|
||
|
||
@task(queue='web') | ||
@task() | ||
def clear_artifacts(version_pk): | ||
"""Remove artifacts from the web servers""" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If not running on just the web queue, docs need updating here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It will still only work on the web servers, but instead run on the |
||
version = Version.objects.get(pk=version_pk) | ||
|
@@ -920,33 +920,19 @@ def clear_artifacts(version_pk): | |
|
||
|
||
def clear_pdf_artifacts(version): | ||
run_on_app_servers('rm -rf %s' | ||
% version.project.get_production_media_path( | ||
type_='pdf', version_slug=version.slug)) | ||
remove_dir(version.project.get_production_media_path( | ||
type_='pdf', version_slug=version.slug)) | ||
|
||
|
||
def clear_epub_artifacts(version): | ||
run_on_app_servers('rm -rf %s' | ||
% version.project.get_production_media_path( | ||
type_='epub', version_slug=version.slug)) | ||
remove_dir(version.project.get_production_media_path( | ||
type_='epub', version_slug=version.slug)) | ||
|
||
|
||
def clear_htmlzip_artifacts(version): | ||
run_on_app_servers('rm -rf %s' | ||
% version.project.get_production_media_path( | ||
type_='htmlzip', version_slug=version.slug)) | ||
remove_dir(version.project.get_production_media_path( | ||
type_='htmlzip', version_slug=version.slug)) | ||
|
||
|
||
def clear_html_artifacts(version): | ||
run_on_app_servers('rm -rf %s' % version.project.rtd_build_path(version=version.slug)) | ||
|
||
|
||
@task(queue='web') | ||
def remove_path_from_web(path): | ||
"""Remove the given path from the web servers file system.""" | ||
# Santity check for spaces in the path since spaces would result in | ||
# deleting unpredictable paths with "rm -rf". | ||
assert ' ' not in path, "No spaces allowed in path" | ||
|
||
# TODO: We need some proper escaping here for the given path. | ||
run_on_app_servers('rm -rf {path}'.format(path=path)) | ||
remove_dir(version.project.rtd_build_path(version=version.slug)) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
from __future__ import absolute_import | ||
import os | ||
import json | ||
import shutil | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we were using a newer version of celery, this would be a good case for chaining the tasks:
http://docs.celeryproject.org/en/latest/userguide/canvas.html#chains
I'd like to use more celery features, if we can get around to upgrading celery at some point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aye. Would be useful for a few things.