From e04d9f586be2be3a2df0db3ba1ae4f36e3e9665a Mon Sep 17 00:00:00 2001 From: Jan Dittberner Date: Fri, 26 Dec 2014 13:14:09 +0100 Subject: [PATCH] define celery routing --- gvafile/gvafile/settings/base.py | 4 ++++ gvafile/osusers/tasks.py | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/gvafile/gvafile/settings/base.py b/gvafile/gvafile/settings/base.py index 5fd8143..9b57ca0 100644 --- a/gvafile/gvafile/settings/base.py +++ b/gvafile/gvafile/settings/base.py @@ -282,6 +282,10 @@ BROKER_URL = get_env_setting('GVAFILE_BROKER_URL') CELERY_RESULT_BACKEND = 'amqp' CELERY_RESULT_PERSISTENT = True CELERY_TASK_RESULT_EXPIRES = None +CELERY_ROUTES = ( + 'osusers.tasks.LdapRouter', + 'osusers.tasks.FileRouter', +) CELERY_ACCEPT_CONTENT = ['yaml', 'json'] CELERY_TASK_SERIALIZER = 'json' CELERY_RESULT_SERIALIZER = 'json' diff --git a/gvafile/osusers/tasks.py b/gvafile/osusers/tasks.py index e386a99..ada2e84 100644 --- a/gvafile/osusers/tasks.py +++ b/gvafile/osusers/tasks.py @@ -25,6 +25,26 @@ SETFACL_CMD = '/usr/bin/setfacl' RM_CMD = '/bin/rm' +class LdapRouter(object): + + def route_for_task(self, task, args=None, kwargs=None): + if 'ldap' in task: + return {'exchange': 'ldap', + 'exchange_type': 'direct', + 'queue': 'ldap'} + return None + + +class FileRouter(object): + + def route_for_task(self, task, args=None, kwargs=None): + if 'file' in task: + return {'exchange': 'file', + 'exchange_type': 'direct', + 'queue': 'file'} + return None + + def _build_sftp_directory_name(username): """ Constructs the SFTP directory name for a given username.