Mercurial > kallithea
diff rhodecode/lib/celerylib/__init__.py @ 1003:9037456bb17f beta
Another better solution for establishing connection with messaging broker in celery.
This one doesn't require celeryconfig.py
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Tue, 08 Feb 2011 03:45:22 +0100 |
parents | 110a00c181de |
children | 7fd45bf17d07 |
line wrap: on
line diff
--- a/rhodecode/lib/celerylib/__init__.py Tue Feb 08 02:57:21 2011 +0100 +++ b/rhodecode/lib/celerylib/__init__.py Tue Feb 08 03:45:22 2011 +0100 @@ -38,6 +38,7 @@ from rhodecode.lib import str2bool from rhodecode.lib.pidlock import DaemonLock, LockHeld +from celery.messaging import establish_connection from pylons import config log = logging.getLogger(__name__) @@ -58,7 +59,17 @@ def run_task(task, *args, **kwargs): if CELERY_ON: try: - t = task.delay(*args, **kwargs) + kw = { + 'hostname':config['app_conf'].get('broker.host'), + 'userid':config['app_conf'].get('broker.user'), + 'password':config['app_conf'].get('broker.password'), + 'virtual_host':config['app_conf'].get('broker.vhost'), + 'port':config['app_conf'].get('broker.port'), + } + conn = establish_connection(**kw) + publisher = task.get_publisher(connection=conn) + t = task.apply_async(args=args, kwargs=kwargs, publisher=publisher) + log.info('running task %s:%s', t.task_id, task) return t except socket.error, e: