remove USE_CELERY option, use built-in CELERY_ALWAYS_EAGER instead
authorRadek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>
Fri, 28 Oct 2011 09:34:00 +0000 (11:34 +0200)
committerRadek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>
Fri, 28 Oct 2011 09:34:00 +0000 (11:34 +0200)
apps/catalogue/models.py
apps/catalogue/test_utils.py
apps/catalogue/utils.py
wolnelektury/settings.py

index 565b759..bb0067f 100644 (file)
@@ -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 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
 
 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))
 
         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():
 
     @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))
 
         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():
 
     @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)
     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):
 
     @classmethod
     def from_xml_file(cls, xml_file, **kwargs):
index 48e9c90..a5f0b4f 100644 (file)
@@ -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
     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)
 
     def tearDown(self):
         shutil.rmtree(settings.MEDIA_ROOT, True)
index 3a8d1b0..29a1857 100644 (file)
@@ -90,6 +90,7 @@ class LockFile(object):
         self.lock.close()
 
 
         self.lock.close()
 
 
+@task
 def create_zip(paths, zip_slug):
     """
     Creates a zip in MEDIA_ROOT/zip directory containing files from path.
 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
     except OSError as oe:
         if oe.errno != ENOENT:
             raise oe
-
-
-@task
-def create_zip_task(*args):
-    return create_zip(*args)
index 0b9fcdf..527b702 100644 (file)
@@ -245,7 +245,6 @@ BROKER_USER = "guest"
 BROKER_PASSWORD = "guest"
 BROKER_VHOST = "/"
 
 BROKER_PASSWORD = "guest"
 BROKER_VHOST = "/"
 
-USE_CELERY = True
 
 # Load localsettings, if they exist
 try:
 
 # Load localsettings, if they exist
 try: