Permalink
Browse files

Allow Celery tasks access to the CKAN config, without adding overhead…

… of the whole CKAN environment.
  • Loading branch information...
1 parent 0191e4d commit 83dcaf3d875d622ee0cd7f3c1f65ec27a970cd10 @davidread davidread committed Sep 18, 2012
Showing with 26 additions and 21 deletions.
  1. +0 −7 ckan/lib/celery_app.py
  2. +19 −10 ckan/lib/cli.py
  3. +7 −4 ckan/lib/search/__init__.py
View
@@ -11,19 +11,13 @@
celery = Celery()
config = ConfigParser.ConfigParser()
-
config_file = os.environ.get('CKAN_CONFIG')
-
if not config_file:
config_file = os.path.join(
os.path.dirname(os.path.abspath(__file__)), '../../development.ini')
config.read(config_file)
-
sqlalchemy_url = pylons_config.get('sqlalchemy.url')
-if not sqlalchemy_url:
- sqlalchemy_url = config.get('app:main', 'sqlalchemy.url')
-
default_config = dict(
BROKER_BACKEND = 'sqlalchemy',
@@ -40,7 +34,6 @@
entry_point.load()()
)
-
celery.conf.update(default_config)
celery.loader.conf.update(default_config)
View
@@ -36,7 +36,8 @@ class CkanCommand(paste.script.command.Command):
default_verbosity = 1
group_name = 'ckan'
- def _load_config(self):
+ def _load_config(self, load_environment=True):
+ '''Load pylons environment configured with CKAN config file'''
from paste.deploy import appconfig
if not self.options.config:
msg = 'No config file supplied'
@@ -47,16 +48,23 @@ def _load_config(self):
fileConfig(self.filename)
conf = appconfig('config:' + self.filename)
assert 'ckan' not in dir() # otherwise loggers would be disabled
- # We have now loaded the config. Now we can import ckan for the
- # first time.
- from ckan.config.environment import load_environment
- load_environment(conf.global_conf, conf.local_conf)
- self.registry=Registry()
- self.registry.prepare()
- import pylons
- self.translator_obj = MockTranslator()
- self.registry.register(pylons.translator, self.translator_obj)
+ if load_environment:
+ # We have now loaded the config. Now we can import ckan for the
+ # first time.
+ from ckan.config.environment import load_environment
+ load_environment(conf.global_conf, conf.local_conf)
+
+ self.registry=Registry()
+ self.registry.prepare()
+ import pylons
+ self.translator_obj = MockTranslator()
+ self.registry.register(pylons.translator, self.translator_obj)
+ else:
+ # Initialize config with the basic options
+ import pylons
+ pylons.config.init_app(conf.global_conf, conf.local_conf,
+ package='ckan', paths=[])
def _setup_app(self):
cmd = paste.script.appinstall.SetupCommand('setup-app')
@@ -805,6 +813,7 @@ def command(self):
sys.exit(1)
def run_(self):
+ self._load_config(load_environment=False)
os.environ['CKAN_CONFIG'] = os.path.abspath(self.options.config)
from ckan.lib.celery_app import celery
celery_args = ['--%s' % arg for arg in self.args[1:]]
@@ -153,11 +153,14 @@ def rebuild(package_id=None,only_missing=False,force=False,refresh=False):
if len(package_ids) == 0:
log.debug('All datasets are already indexed')
return
+ elif refresh:
+ log.debug('Refreshing the index...')
+ # The index is not previously cleared,
+ # but remove from the index any stray ones
+ # TODO Clear stray ones
else:
- log.debug('Rebuilding the whole index...')
- # When refreshing, the index is not previously cleared
- if not refresh:
- package_index.clear()
+ log.debug('Rebuilding the whole index from scratch...')
+ package_index.clear()
for pkg_id in package_ids:
try:

0 comments on commit 83dcaf3

Please sign in to comment.