comparison rhodecode/lib/celerypylons/loader.py @ 776:f6c613fba757 beta

Celery is configured by the .ini files and run from paster now removed celeryconfig, added homebrew celery-pylons, added paster celeryd command, fixed tasks to use pylons configs, sqlalchemy sessions
author Marcin Kuzminski <marcin@python-works.com>
date Sat, 27 Nov 2010 01:27:24 +0100
parents
children 3a7f5b1a19dd
comparison
equal deleted inserted replaced
775:aaf2fc59a39a 776:f6c613fba757
1 from celery.loaders.base import BaseLoader
2 from pylons import config
3
4 to_pylons = lambda x: x.replace('_', '.').lower()
5 to_celery = lambda x: x.replace('.', '_').upper()
6
7 LIST_PARAMS = """CELERY_IMPORTS ADMINS ROUTES""".split()
8
9
10 class PylonsSettingsProxy(object):
11 """Pylons Settings Proxy
12
13 Proxies settings from pylons.config
14
15 """
16 def __getattr__(self, key):
17 pylons_key = to_pylons(key)
18 try:
19 value = config[pylons_key]
20 if key in LIST_PARAMS: return value.split()
21 return self.type_converter(value)
22 except KeyError:
23 raise AttributeError(pylons_key)
24
25 def __setattr__(self, key, value):
26 pylons_key = to_pylons(key)
27 config[pylons_key] = value
28
29
30 def type_converter(self, value):
31 #cast to int
32 if value.isdigit():
33 return int(value)
34
35 #cast to bool
36 if value.lower() in ['true', 'false']:
37 return value.lower() == 'true'
38
39 return value
40
41 class PylonsLoader(BaseLoader):
42 """Pylons celery loader
43
44 Maps the celery config onto pylons.config
45
46 """
47 def read_configuration(self):
48 self.configured = True
49 return PylonsSettingsProxy()
50
51 def on_worker_init(self):
52 """
53 Import task modules.
54 """
55 self.import_default_modules()