Mercurial > public > src > rhodecode
changeset 1066: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 | 3a7f5b1a19dd |
children | 7fd45bf17d07 |
files | celeryconfig.py rhodecode/lib/celerylib/__init__.py |
diffstat | 2 files changed, 12 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/celeryconfig.py Tue Feb 08 02:57:21 2011 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,4 +0,0 @@ -## Broker settings. -BROKER_VHOST = "rabbitmqhost" -BROKER_USER = "rabbitmq" -BROKER_PASSWORD = "qweqwe"
--- 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: