Force imports of stuff like mediagoblin.process_media which has tasks we need
authorChristopher Allan Webber <cwebber@dustycloud.org>
Wed, 4 May 2011 02:48:02 +0000 (21:48 -0500)
committerChristopher Allan Webber <cwebber@dustycloud.org>
Wed, 4 May 2011 02:48:02 +0000 (21:48 -0500)
mediagoblin/celery_setup/__init__.py
mediagoblin/tests/test_celery_setup.py

index 3a7f2a5d6ac69e5650aca503c361a39f129e6a97..551b2741d510166f4bec3406efd8c1aec4263cfb 100644 (file)
@@ -70,6 +70,8 @@ def asfloat(obj):
             "Bad float value: %r" % obj)
 
 
+MANDATORY_CELERY_IMPORTS = ['mediagoblin.process_media']
+
 DEFAULT_SETTINGS_MODULE = 'mediagoblin.celery_setup.dummy_settings_module'
 
 def setup_celery_from_config(app_config, global_config,
@@ -130,6 +132,10 @@ def setup_celery_from_config(app_config, global_config,
             value = aslist(value)
         celery_settings[key] = value
 
+    # add mandatory celery imports
+    celery_imports = celery_settings.setdefault('CELERY_IMPORTS', [])
+    celery_imports.extend(MANDATORY_CELERY_IMPORTS)
+
     __import__(settings_module)
     this_module = sys.modules[settings_module]
 
index da18b0ef58c71507a143510844518db3fc0bb86c..558eb458abf38b4dca119933c4abd529fa865065 100644 (file)
@@ -45,7 +45,7 @@ def test_setup_celery_from_config():
     assert isinstance(fake_celery_module.CELERYD_ETA_SCHEDULER_PRECISION, float)
     assert fake_celery_module.CELERY_RESULT_PERSISTENT is True
     assert fake_celery_module.CELERY_IMPORTS == [
-        'foo.bar.baz', 'this.is.an.import']
+        'foo.bar.baz', 'this.is.an.import', 'mediagoblin.process_media']
     assert fake_celery_module.CELERY_MONGODB_BACKEND_SETTINGS == {
         'database': 'mediagoblin'}
     assert fake_celery_module.CELERY_RESULT_BACKEND == 'mongodb'
@@ -74,7 +74,7 @@ def test_setup_celery_from_config():
     assert isinstance(fake_celery_module.CELERYD_ETA_SCHEDULER_PRECISION, float)
     assert fake_celery_module.CELERY_RESULT_PERSISTENT is False
     assert fake_celery_module.CELERY_IMPORTS == [
-        'baz.bar.foo', 'import.is.a.this']
+        'baz.bar.foo', 'import.is.a.this', 'mediagoblin.process_media']
     assert fake_celery_module.CELERY_MONGODB_BACKEND_SETTINGS == {
         'database': 'captain_lollerskates',
         'host': 'mongodb.example.org',