diff --git a/kallithea/lib/celerypylons/__init__.py b/kallithea/lib/celerypylons/__init__.py --- a/kallithea/lib/celerypylons/__init__.py +++ b/kallithea/lib/celerypylons/__init__.py @@ -8,17 +8,19 @@ the `CELERY_LOADER` environment variable read it. That environment variable must be set *before* importing celery. To ensure that, we wrap celery in this module. -Also, the loader depends on Pylons being configured to it can read the Celery -configuration out of it. To make sure that really is the case and give an early +We read the configuration from tg.config, thus it must be initialized before +loading this module. To make sure that really is the case and give an early warning, we check one of the mandatory settings. This module must thus not be imported in global scope but must be imported on -demand in function scope. +demand in function scope after tg.config has been initialized. """ import os import warnings +import celery.app + # Verify Pylons configuration has been loaded from tg import config assert config['celery.imports'] == 'kallithea.lib.celerylib.tasks', 'Kallithea Celery configuration has not been loaded' @@ -29,8 +31,9 @@ if os.environ.get('CELERY_LOADER', CELER warnings.warn("'CELERY_LOADER' environment variable will be overridden by celery-pylons.") os.environ['CELERY_LOADER'] = CELERYPYLONS_LOADER -# Import (and expose) celery, thus immediately triggering use of the custom Pylons loader -import celery.app as app +# Create celery app, thus immediately triggering use of the custom Pylons loader +app = celery.app.app_or_default() + import celery.result as result from celery.task import task from celery.bin import worker diff --git a/kallithea/lib/paster_commands/celeryd.py b/kallithea/lib/paster_commands/celeryd.py --- a/kallithea/lib/paster_commands/celeryd.py +++ b/kallithea/lib/paster_commands/celeryd.py @@ -21,7 +21,7 @@ class Command(BasePasterCommand): 'file before running celeryd') from kallithea.lib import celerypylons - cmd = celerypylons.worker.worker(celerypylons.app.app_or_default()) + cmd = celerypylons.worker.worker(celerypylons.app) celery_args = args.celery_args if '--' in celery_args: