define celery routing

This commit is contained in:
Jan Dittberner 2014-12-26 13:13:57 +01:00
parent 787a943c69
commit ac4693d0eb
2 changed files with 24 additions and 0 deletions

View file

@ -290,6 +290,10 @@ BROKER_URL = get_env_setting('GVALDAP_BROKER_URL')
CELERY_RESULT_BACKEND = 'amqp' CELERY_RESULT_BACKEND = 'amqp'
CELERY_RESULT_PERSISTENT = True CELERY_RESULT_PERSISTENT = True
CELERY_TASK_RESULT_EXPIRES = None CELERY_TASK_RESULT_EXPIRES = None
CELERY_ROUTES = (
'osusers.tasks.LdapRouter',
'osusers.tasks.FileRouter',
)
CELERY_ACCEPT_CONTENT = ['yaml', 'json'] CELERY_ACCEPT_CONTENT = ['yaml', 'json']
CELERY_TASK_SERAILIZER = 'json' CELERY_TASK_SERAILIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json' CELERY_RESULT_SERIALIZER = 'json'

View file

@ -21,6 +21,26 @@ from ldapentities.models import (
_logger = get_task_logger(__name__) _logger = get_task_logger(__name__)
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
@shared_task @shared_task
def create_ldap_group(groupname, gid, descr): def create_ldap_group(groupname, gid, descr):
""" """