From f4a7254db57835252ea0cf23ab45d0baea71dc38 Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Fri, 28 Oct 2011 11:34:00 +0200 Subject: [PATCH] remove USE_CELERY option, use built-in CELERY_ALWAYS_EAGER instead --- apps/catalogue/models.py | 26 +++++++------------------- apps/catalogue/test_utils.py | 2 +- apps/catalogue/utils.py | 6 +----- wolnelektury/settings.py | 1 - 4 files changed, 9 insertions(+), 26 deletions(-) diff --git a/apps/catalogue/models.py b/apps/catalogue/models.py index 565b759ce..bb0067f35 100644 --- a/apps/catalogue/models.py +++ b/apps/catalogue/models.py @@ -22,7 +22,7 @@ from django.conf import settings from newtagging.models import TagBase, tags_updated from newtagging import managers from catalogue.fields import JSONField, OverwritingFileField -from catalogue.utils import ExistingFile, ORMDocProvider, create_zip_task, remove_zip +from catalogue.utils import ExistingFile, ORMDocProvider, create_zip, remove_zip from librarian import dcparser, html, epub, NoDublinCore import mutagen @@ -606,12 +606,8 @@ class Book(models.Model): paths = filter(lambda x: x is not None, map(lambda b: b.epub_file and b.epub_file.path or None, books)) - if settings.USE_CELERY: - result = create_zip_task.delay(paths, settings.ALL_EPUB_ZIP) - return result.wait() - else: - result = create_zip_task(paths, settings.ALL_EPUB_ZIP) - return result + result = create_zip_task.delay(paths, settings.ALL_EPUB_ZIP) + return result.wait() @staticmethod def zip_pdf(): @@ -619,12 +615,8 @@ class Book(models.Model): paths = filter(lambda x: x is not None, map(lambda b: b.pdf_file and b.pdf_file.path or None, books)) - if settings.USE_CELERY: - result = create_zip_task.delay(paths, settings.ALL_PDF_ZIP) - return result.wait() - else: - result = create_zip_task(paths, settings.ALL_PDF_ZIP) - return result + result = create_zip_task.delay(paths, settings.ALL_PDF_ZIP) + return result.wait() @staticmethod def zip_mobi(): @@ -638,12 +630,8 @@ class Book(models.Model): def zip_audiobooks(self): bm = BookMedia.objects.filter(book=self) paths = map(lambda bm: bm.file.path, bm) - if settings.USE_CELERY: - result = create_zip_task.delay(paths, self.slug) - return result.wait() - else: - result = create_zip_task(paths, self.slug) - return result + result = create_zip_task.delay(paths, self.slug) + return result.wait() @classmethod def from_xml_file(cls, xml_file, **kwargs): diff --git a/apps/catalogue/test_utils.py b/apps/catalogue/test_utils.py index 48e9c90ad..a5f0b4fef 100644 --- a/apps/catalogue/test_utils.py +++ b/apps/catalogue/test_utils.py @@ -11,7 +11,7 @@ class WLTestCase(TestCase): def setUp(self): self._MEDIA_ROOT, settings.MEDIA_ROOT = settings.MEDIA_ROOT, tempfile.mkdtemp(prefix='djangotest_') settings.NO_BUILD_PDF = settings.NO_BUILD_MOBI = settings.NO_BUILD_EPUB = settings.NO_BUILD_TXT = True - settings.USE_CELERY = False + settings.CELERY_ALWAYS_EAGER = True def tearDown(self): shutil.rmtree(settings.MEDIA_ROOT, True) diff --git a/apps/catalogue/utils.py b/apps/catalogue/utils.py index 3a8d1b027..29a1857b0 100644 --- a/apps/catalogue/utils.py +++ b/apps/catalogue/utils.py @@ -90,6 +90,7 @@ class LockFile(object): self.lock.close() +@task def create_zip(paths, zip_slug): """ Creates a zip in MEDIA_ROOT/zip directory containing files from path. @@ -128,8 +129,3 @@ def remove_zip(zip_slug): except OSError as oe: if oe.errno != ENOENT: raise oe - - -@task -def create_zip_task(*args): - return create_zip(*args) diff --git a/wolnelektury/settings.py b/wolnelektury/settings.py index 0b9fcdfa0..527b70277 100644 --- a/wolnelektury/settings.py +++ b/wolnelektury/settings.py @@ -245,7 +245,6 @@ BROKER_USER = "guest" BROKER_PASSWORD = "guest" BROKER_VHOST = "/" -USE_CELERY = True # Load localsettings, if they exist try: -- 2.20.1