def __init__(self, host=None, port=None, db=None, password=None, expires=None, max_connections=None, url=None, connection_pool=None, new_join=False, **kwargs): super(RedisBackend, self).__init__(**kwargs) conf = self.app.conf if self.redis is None: raise ImproperlyConfigured(REDIS_MISSING) self._client_capabilities = self._detect_client_capabilities() # For compatibility with the old REDIS_* configuration keys. def _get(key): for prefix in 'CELERY_REDIS_{0}', 'REDIS_{0}': try: return conf[prefix.format(key)] except KeyError: pass if host and '://' in host: url = host host = None self.max_connections = (max_connections or _get('MAX_CONNECTIONS') or self.max_connections) self._ConnectionPool = connection_pool self.connparams = { 'host': _get('HOST') or 'localhost', 'port': _get('PORT') or 6379, 'db': _get('DB') or 0, 'password': _get('PASSWORD'), 'max_connections': self.max_connections, } if url: self.connparams = self._params_from_url(url, self.connparams) self.url = url self.expires = self.prepare_expires(expires, type=int) try: new_join = strtobool(self.connparams.pop('new_join')) except KeyError: pass if new_join: self.apply_chord = self._new_chord_apply self.on_chord_part_return = self._new_chord_return self.connection_errors, self.channel_errors = ( get_redis_error_classes() if get_redis_error_classes else ((), ()))
def __init__(self, host=None, port=None, db=None, password=None, expires=None, max_connections=None, url=None, connection_pool=None, new_join=False, **kwargs): super(RedisBackend, self).__init__(**kwargs) conf = self.app.conf if self.redis is None: raise ImproperlyConfigured(REDIS_MISSING) self._client_capabilities = self._detect_client_capabilities() # For compatibility with the old REDIS_* configuration keys. def _get(key): for prefix in 'CELERY_REDIS_{0}', 'REDIS_{0}': try: return conf[prefix.format(key)] except KeyError: pass if host and '://' in host: url = host host = None self.max_connections = ( max_connections or _get('MAX_CONNECTIONS') or self.max_connections ) self._ConnectionPool = connection_pool self.connparams = { 'host': _get('HOST') or 'localhost', 'port': _get('PORT') or 6379, 'db': _get('DB') or 0, 'password': _get('PASSWORD'), 'max_connections': self.max_connections, } if url: self.connparams = self._params_from_url(url, self.connparams) self.url = url self.expires = self.prepare_expires(expires, type=int) try: new_join = strtobool(self.connparams.pop('new_join')) except KeyError: pass if new_join: self.apply_chord = self._new_chord_apply self.on_chord_part_return = self._new_chord_return self.connection_errors, self.channel_errors = ( get_redis_error_classes() if get_redis_error_classes else ((), ()))
def __init__(self, *args, **kwargs): logger.info('args:%s, kwargs:%s', args, kwargs) super(RedisClusterBackend, self).__init__(expires_type=int, **kwargs) conf = self.app.conf if self.redis is None: raise ImproperlyConfigured(REDIS_MISSING) # For compatibility with the old REDIS_* configuration keys. def _get(key): for prefix in 'CELERY_REDIS_{0}', 'REDIS_{0}': try: return conf[prefix.format(key)] except KeyError: pass self.conn_params = self.app.conf.get( 'CELERY_REDIS_CLUSTER_SETTINGS', { 'startup_nodes': [{ 'host': _get('HOST') or 'localhost', 'port': _get('PORT') or 6379 }] }) if self.conn_params is not None: if not isinstance(self.conn_params, dict): raise ImproperlyConfigured( 'RedisCluster backend settings should be grouped in a dict' ) try: new_join = strtobool(self.conn_params.pop('new_join')) if new_join: self.apply_chord = self._new_chord_apply self.on_chord_part_return = self._new_chord_return except KeyError: pass self.expires = self.prepare_expires(None, type=int) self.connection_errors, self.channel_errors = ( get_redis_error_classes() if get_redis_error_classes else ((), ()))
def __init__(self, host=None, port=None, db=None, password=None, max_connections=None, url=None, connection_pool=None, new_join=False, **kwargs): super(RedisBackend, self).__init__(expires_type=int, **kwargs) _get = self.app.conf.get if self.redis is None: raise ImproperlyConfigured(REDIS_MISSING) if host and '://' in host: url = host host = None self.max_connections = ( max_connections or _get('redis_max_connections') or self.max_connections ) self._ConnectionPool = connection_pool self.connparams = { 'host': _get('redis_host') or 'localhost', 'port': _get('redis_port') or 6379, 'db': _get('redis_db') or 0, 'password': _get('redis_password'), 'socket_timeout': _get('redis_socket_timeout'), 'max_connections': self.max_connections, } if url: self.connparams = self._params_from_url(url, self.connparams) self.url = url try: new_join = strtobool(self.connparams.pop('new_join')) except KeyError: pass if new_join: self.apply_chord = self._new_chord_apply self.on_chord_part_return = self._new_chord_return self.connection_errors, self.channel_errors = ( get_redis_error_classes() if get_redis_error_classes else ((), ()))
def __init__(self, *args, **kwargs): super(RedisClusterBackend, self).__init__(expires_type=int, **kwargs) conf = self.app.conf if self.redis is None: raise ImproperlyConfigured(REDIS_MISSING) # For compatibility with the old REDIS_* configuration keys. def _get(key): for prefix in 'CELERY_REDIS_{0}', 'REDIS_{0}': try: return conf[prefix.format(key)] except KeyError: pass self.conn_params = self.app.conf.get('CELERY_REDIS_CLUSTER_SETTINGS', { 'startup_nodes': [{'host': _get('HOST') or 'localhost', 'port': _get('PORT') or 6379}] }) if self.conn_params is not None: if not isinstance(self.conn_params, dict): raise ImproperlyConfigured( 'RedisCluster backend settings should be grouped in a dict') try: new_join = strtobool(self.conn_params.pop('new_join')) if new_join: self.apply_chord = self._new_chord_apply self.on_chord_part_return = self._new_chord_return except KeyError: pass self.expires = self.prepare_expires(None, type=int) self.connection_errors, self.channel_errors = ( get_redis_error_classes() if get_redis_error_classes else ((), ()))
import os import sys import warnings from celery.datastructures import AttributeDict from celery.exceptions import NotConfigured from celery.utils import strtobool from celery.utils.imports import NotAPackage, find_module from .base import BaseLoader DEFAULT_CONFIG_MODULE = 'celeryconfig' #: Warns if configuration file is missing if :envvar:`C_WNOCONF` is set. C_WNOCONF = strtobool(os.environ.get('C_WNOCONF', False)) CONFIG_INVALID_NAME = """ Error: Module '%(module)s' doesn't exist, or it's not a valid \ Python module name. """ CONFIG_WITH_SUFFIX = CONFIG_INVALID_NAME + """ Did you mean '%(suggest)s'? """ class Loader(BaseLoader): """The loader used by the default app.""" def setup_settings(self, settingsdict):
import os import warnings from celery.datastructures import DictAttribute from celery.exceptions import NotConfigured from celery.utils import strtobool from .base import BaseLoader __all__ = ['Loader', 'DEFAULT_CONFIG_MODULE'] DEFAULT_CONFIG_MODULE = 'celeryconfig' #: Warns if configuration file is missing if :envvar:`C_WNOCONF` is set. C_WNOCONF = strtobool(os.environ.get('C_WNOCONF', False)) class Loader(BaseLoader): """The loader used by the default app.""" def setup_settings(self, settingsdict): return DictAttribute(settingsdict) def read_configuration(self, fail_silently=True): """Read configuration from :file:`celeryconfig.py` and configure celery and Django so it can be used by regular Python.""" configname = os.environ.get('CELERY_CONFIG_MODULE', DEFAULT_CONFIG_MODULE) try: usercfg = self._import_config_module(configname) except ImportError:
import os import sys import warnings from celery.datastructures import AttributeDict from celery.exceptions import NotConfigured from celery.utils import strtobool from celery.utils.imports import NotAPackage, find_module from .base import BaseLoader DEFAULT_CONFIG_MODULE = "celeryconfig" #: Warns if configuration file is missing if :envvar:`C_WNOCONF` is set. C_WNOCONF = strtobool(os.environ.get("C_WNOCONF", False)) CONFIG_INVALID_NAME = """ Error: Module '%(module)s' doesn't exist, or it's not a valid \ Python module name. """ CONFIG_WITH_SUFFIX = ( CONFIG_INVALID_NAME + """ Did you mean '%(suggest)s'? """ ) class Loader(BaseLoader):
import os import sys import warnings from celery.datastructures import AttributeDict from celery.exceptions import NotConfigured from celery.utils import strtobool from celery.utils.imports import NotAPackage, find_module from .base import BaseLoader DEFAULT_CONFIG_MODULE = "celeryconfig" #: Warns if configuration file is missing if :envvar:`C_WNOCONF` is set. C_WNOCONF = strtobool(os.environ.get("C_WNOCONF", False)) CONFIG_INVALID_NAME = """ Error: Module '%(module)s' doesn't exist, or it's not a valid \ Python module name. """ CONFIG_WITH_SUFFIX = CONFIG_INVALID_NAME + """ Did you mean '%(suggest)s'? """ class Loader(BaseLoader): """The loader used by the default app.""" def setup_settings(self, settingsdict): return AttributeDict(settingsdict)