def __init__(self, *args, **kwargs): """Initialize MongoDB backend instance. :raises celery.exceptions.ImproperlyConfigured: if module :mod:`pymongo` is not available. """ super(MongoBackend, self).__init__(*args, **kwargs) self.expires = kwargs.get('expires') or maybe_timedelta( self.app.conf.CELERY_TASK_RESULT_EXPIRES) if not pymongo: raise ImproperlyConfigured( 'You need to install the pymongo library to use the ' 'MongoDB backend.') config = self.app.conf.get('CELERY_MONGODB_BACKEND_SETTINGS', None) if config is not None: if not isinstance(config, dict): raise ImproperlyConfigured( 'MongoDB backend settings should be grouped in a dict') self.mongodb_host = config.get('host', self.mongodb_host) self.mongodb_port = int(config.get('port', self.mongodb_port)) self.mongodb_user = config.get('user', self.mongodb_user) self.mongodb_password = config.get('password', self.mongodb_password) self.mongodb_database = config.get('database', self.mongodb_database) self.mongodb_taskmeta_collection = config.get( 'taskmeta_collection', self.mongodb_taskmeta_collection) self.mongodb_max_pool_size = config.get('max_pool_size', self.mongodb_max_pool_size) self._connection = None
def __init__(self, url=None, *args, **kwargs): super(CouchBaseBackend, self).__init__(*args, **kwargs) self.url = url self.expires = kwargs.get('expires') or maybe_timedelta( self.app.conf.CELERY_TASK_RESULT_EXPIRES) if Couchbase is None: raise ImproperlyConfigured( 'You need to install the couchbase library to use the ' 'CouchBase backend.', ) uhost = uport = uname = upass = ubucket = None if url: _, uhost, uport, uname, upass, ubucket, _ = _parse_url(url) ubucket = ubucket.strip('/') if ubucket else None config = self.app.conf.get('CELERY_COUCHBASE_BACKEND_SETTINGS', None) if config is not None: if not isinstance(config, dict): raise ImproperlyConfigured( 'Couchbase backend settings should be grouped in a dict', ) else: config = {} self.host = uhost or config.get('host', self.host) self.port = int(uport or config.get('port', self.port)) self.bucket = ubucket or config.get('bucket', self.bucket) self.username = uname or config.get('username', self.username) self.password = upass or config.get('password', self.password) self._connection = None
def __init__(self, *args, **kwargs): """Initialize MongoDB backend instance. :raises celery.exceptions.ImproperlyConfigured: if module :mod:`pymongo` is not available. """ super(MongoBackend, self).__init__(*args, **kwargs) self.expires = kwargs.get('expires') or maybe_timedelta( self.app.conf.CELERY_TASK_RESULT_EXPIRES) if not pymongo: raise ImproperlyConfigured( 'You need to install the pymongo library to use the ' 'MongoDB backend.') config = self.app.conf.get('CELERY_MONGODB_BACKEND_SETTINGS', None) if config is not None: if not isinstance(config, dict): raise ImproperlyConfigured( 'MongoDB backend settings should be grouped in a dict') self.mongodb_host = config.get('host', self.mongodb_host) self.mongodb_port = int(config.get('port', self.mongodb_port)) self.mongodb_user = config.get('user', self.mongodb_user) self.mongodb_password = config.get( 'password', self.mongodb_password) self.mongodb_database = config.get( 'database', self.mongodb_database) self.mongodb_taskmeta_collection = config.get( 'taskmeta_collection', self.mongodb_taskmeta_collection) self.mongodb_max_pool_size = config.get( 'max_pool_size', self.mongodb_max_pool_size) self._connection = None
def __init__(self, dburi=None, expires=None, engine_options=None, url=None, **kwargs): # The `url` argument was added later and is used by # the app to set backend by url (celery.backends.get_backend_by_url) super(DatabaseBackend, self).__init__(**kwargs) conf = self.app.conf self.expires = maybe_timedelta(self.prepare_expires(expires)) self.dburi = url or dburi or conf.CELERY_RESULT_DBURI self.engine_options = dict(engine_options or {}, **conf.CELERY_RESULT_ENGINE_OPTIONS or {}) self.short_lived_sessions = kwargs.get( 'short_lived_sessions', conf.CELERY_RESULT_DB_SHORT_LIVED_SESSIONS, ) tablenames = conf.CELERY_RESULT_DB_TABLENAMES or {} Task.__table__.name = tablenames.get('task', 'celery_taskmeta') TaskSet.__table__.name = tablenames.get('group', 'celery_tasksetmeta') if not self.dburi: raise ImproperlyConfigured( 'Missing connection string! Do you have ' 'CELERY_RESULT_DBURI set to a real value?')
def __init__(self, *args, **kwargs): """Initialize MongoDB backend instance. :raises celery.exceptions.ImproperlyConfigured: if module :mod:`pymongo` is not available. """ super(MongoBackend, self).__init__(*args, **kwargs) self.expires = kwargs.get("expires") or maybe_timedelta( self.app.conf.CELERY_TASK_RESULT_EXPIRES) if not pymongo: raise ImproperlyConfigured( "You need to install the pymongo library to use the " "MongoDB backend.") config = self.app.conf.get("CELERY_MONGODB_BACKEND_SETTINGS", None) if config is not None: if not isinstance(config, dict): raise ImproperlyConfigured( "MongoDB backend settings should be grouped in a dict") self.mongodb_host = config.get("host", self.mongodb_host) self.mongodb_port = int(config.get("port", self.mongodb_port)) self.mongodb_user = config.get("user", self.mongodb_user) self.mongodb_password = config.get( "password", self.mongodb_password) self.mongodb_database = config.get( "database", self.mongodb_database) self.mongodb_taskmeta_collection = config.get( "taskmeta_collection", self.mongodb_taskmeta_collection) self._connection = None
def __init__(self, *args, **kwargs): """Initialize RethinkDB backend instance. :raises celery.exceptions.ImproperlyConfigured: if module :mod:`rethinkdb` is not available. """ self.options = {} super(RethinkBackend, self).__init__(*args, **kwargs) self.expires = kwargs.get('expires') or maybe_timedelta( self.app.conf.CELERY_TASK_RESULT_EXPIRES) if not r: raise ImproperlyConfigured( 'You need to install the rethinkdb library to use the ' 'RethinkDB backend.') config = self.app.conf.get('CELERY_RETHINKDB_BACKEND_SETTINGS') if config is not None: if not isinstance(config, dict): raise ImproperlyConfigured( 'RethinkDB backend settings should be grouped in a dict') config = dict(config) # do not modify original self.host = config.pop('host', self.host) self.port = int(config.pop('port', self.port)) self.database_name = config.pop('db', self.database_name) self.auth_key = config.pop('auth_key', self.auth_key) self.timeout = config.pop('timeout', self.timeout) self.table_name = config.pop('table', self.table_name) self.options = dict(config, **config.pop('options', None) or {})
def __init__(self, *args, **kwargs): """Initialize MongoDB backend instance. :raises celery.exceptions.ImproperlyConfigured: if module :mod:`pymongo` is not available. """ super(MongoBackend, self).__init__(*args, **kwargs) self.expires = kwargs.get("expires") or maybe_timedelta( self.app.conf.CELERY_TASK_RESULT_EXPIRES) if not pymongo: raise ImproperlyConfigured( "You need to install the pymongo library to use the " "MongoDB backend.") config = self.app.conf.get("CELERY_MONGODB_BACKEND_SETTINGS", None) if config is not None: if not isinstance(config, dict): raise ImproperlyConfigured( "MongoDB backend settings should be grouped in a dict") self.mongodb_host = config.get("host", self.mongodb_host) self.mongodb_port = int(config.get("port", self.mongodb_port)) self.mongodb_user = config.get("user", self.mongodb_user) self.mongodb_password = config.get("password", self.mongodb_password) self.mongodb_database = config.get("database", self.mongodb_database) self.mongodb_taskmeta_collection = config.get( "taskmeta_collection", self.mongodb_taskmeta_collection) self._connection = None self._database = None
def __init__(self, servers=None, keyspace=None, column_family=None, cassandra_options=None, **kwargs): """Initialize Cassandra backend. Raises :class:`celery.exceptions.ImproperlyConfigured` if the :setting:`CASSANDRA_SERVERS` setting is not set. """ super(CassandraBackend, self).__init__(**kwargs) self.logger = self.app.log.setup_logger( name="celery.backends.cassandra") self.result_expires = kwargs.get("result_expires") or \ maybe_timedelta( self.app.conf.CELERY_TASK_RESULT_EXPIRES) if not pycassa: raise ImproperlyConfigured( "You need to install the pycassa library to use the " "Cassandra backend. See https://github.com/pycassa/pycassa") self.servers = servers or \ self.app.conf.get("CASSANDRA_SERVERS", self.servers) self.keyspace = keyspace or \ self.app.conf.get("CASSANDRA_KEYSPACE", self.keyspace) self.column_family = column_family or \ self.app.conf.get("CASSANDRA_COLUMN_FAMILY", self.column_family) self.cassandra_options = dict( cassandra_options or {}, **self.app.conf.get("CASSANDRA_OPTIONS", {})) read_cons = self.app.conf.get("CASSANDRA_READ_CONSISTENCY", "LOCAL_QUORUM") write_cons = self.app.conf.get("CASSANDRA_WRITE_CONSISTENCY", "LOCAL_QUORUM") try: self.read_consistency = getattr(pycassa.ConsistencyLevel, read_cons) except AttributeError: self.read_consistency = pycassa.ConsistencyLevel.LOCAL_QUORUM try: self.write_consistency = getattr(pycassa.ConsistencyLevel, write_cons) except AttributeError: self.write_consistency = pycassa.ConsistencyLevel.LOCAL_QUORUM if not self.servers or not self.keyspace or not self.column_family: raise ImproperlyConfigured("Cassandra backend not configured.") self._column_family = None
def __init__(self, dburi=None, expires=None, engine_options=None, **kwargs): super(DatabaseBackend, self).__init__(**kwargs) self.expires = maybe_timedelta(self.prepare_expires(expires)) self.dburi = dburi or self.app.conf.CELERY_RESULT_DBURI self.engine_options = dict(engine_options or {}, **self.app.conf.CELERY_RESULT_ENGINE_OPTIONS or {}) if not self.dburi: raise ImproperlyConfigured( "Missing connection string! Do you have " "CELERY_RESULT_DBURI set to a real value?")
def __init__(self, servers=None, keyspace=None, column_family=None, cassandra_options=None, detailed_mode=False, **kwargs): """Initialize Cassandra backend. Raises :class:`celery.exceptions.ImproperlyConfigured` if the :setting:`CASSANDRA_SERVERS` setting is not set. """ super(CassandraBackend, self).__init__(**kwargs) self.logger = self.app.log.setup_logger( name="celery.backends.cassandra") self.expires = kwargs.get("expires") or maybe_timedelta( self.app.conf.CELERY_TASK_RESULT_EXPIRES) if not pycassa: raise ImproperlyConfigured( "You need to install the pycassa library to use the " "Cassandra backend. See https://github.com/pycassa/pycassa") conf = self.app.conf self.servers = (servers or conf.get("CASSANDRA_SERVERS") or self.servers) self.keyspace = (keyspace or conf.get("CASSANDRA_KEYSPACE") or self.keyspace) self.column_family = (column_family or conf.get("CASSANDRA_COLUMN_FAMILY") or self.column_family) self.cassandra_options = dict(conf.get("CASSANDRA_OPTIONS") or {}, **cassandra_options or {}) self.detailed_mode = (detailed_mode or conf.get("CASSANDRA_DETAILED_MODE") or self.detailed_mode) read_cons = conf.get("CASSANDRA_READ_CONSISTENCY") or "LOCAL_QUORUM" write_cons = conf.get("CASSANDRA_WRITE_CONSISTENCY") or "LOCAL_QUORUM" try: self.read_consistency = getattr(pycassa.ConsistencyLevel, read_cons) except AttributeError: self.read_consistency = pycassa.ConsistencyLevel.LOCAL_QUORUM try: self.write_consistency = getattr(pycassa.ConsistencyLevel, write_cons) except AttributeError: self.write_consistency = pycassa.ConsistencyLevel.LOCAL_QUORUM if not self.servers or not self.keyspace or not self.column_family: raise ImproperlyConfigured( "Cassandra backend not configured.") self._column_family = None
def __init__(self, servers=None, keyspace=None, column_family=None, cassandra_options=None, detailed_mode=False, **kwargs): """Initialize Cassandra backend. Raises :class:`celery.exceptions.ImproperlyConfigured` if the :setting:`CASSANDRA_SERVERS` setting is not set. """ super(CassandraBackend, self).__init__(**kwargs) self.expires = kwargs.get('expires') or maybe_timedelta( self.app.conf.CELERY_TASK_RESULT_EXPIRES) if not pycassa: raise ImproperlyConfigured( 'You need to install the pycassa library to use the ' 'Cassandra backend. See https://github.com/pycassa/pycassa') conf = self.app.conf self.servers = (servers or conf.get('CASSANDRA_SERVERS') or self.servers) self.keyspace = (keyspace or conf.get('CASSANDRA_KEYSPACE') or self.keyspace) self.column_family = (column_family or conf.get('CASSANDRA_COLUMN_FAMILY') or self.column_family) self.cassandra_options = dict( conf.get('CASSANDRA_OPTIONS') or {}, **cassandra_options or {}) self.detailed_mode = (detailed_mode or conf.get('CASSANDRA_DETAILED_MODE') or self.detailed_mode) read_cons = conf.get('CASSANDRA_READ_CONSISTENCY') or 'LOCAL_QUORUM' write_cons = conf.get('CASSANDRA_WRITE_CONSISTENCY') or 'LOCAL_QUORUM' try: self.read_consistency = getattr(pycassa.ConsistencyLevel, read_cons) except AttributeError: self.read_consistency = pycassa.ConsistencyLevel.LOCAL_QUORUM try: self.write_consistency = getattr(pycassa.ConsistencyLevel, write_cons) except AttributeError: self.write_consistency = pycassa.ConsistencyLevel.LOCAL_QUORUM if not self.servers or not self.keyspace or not self.column_family: raise ImproperlyConfigured('Cassandra backend not configured.') self._column_family = None
def __init__(self, dburi=None, result_expires=None, engine_options=None, **kwargs): super(DatabaseBackend, self).__init__(**kwargs) self.result_expires = result_expires or \ maybe_timedelta( self.app.conf.CELERY_TASK_RESULT_EXPIRES) self.dburi = dburi or self.app.conf.CELERY_RESULT_DBURI self.engine_options = dict(engine_options or {}, **self.app.conf.CELERY_RESULT_ENGINE_OPTIONS or {}) if not self.dburi: raise ImproperlyConfigured( "Missing connection string! Do you have " "CELERY_RESULT_DBURI set to a real value?")
def __init__(self, dburi=None, expires=None, engine_options=None, **kwargs): super(DatabaseBackend, self).__init__(**kwargs) conf = self.app.conf self.expires = maybe_timedelta(self.prepare_expires(expires)) self.dburi = dburi or conf.CELERY_RESULT_DBURI self.engine_options = dict(engine_options or {}, **conf.CELERY_RESULT_ENGINE_OPTIONS or {}) self.short_lived_sessions = kwargs.get("short_lived_sessions", conf.CELERY_RESULT_DB_SHORT_LIVED_SESSIONS) if not self.dburi: raise ImproperlyConfigured( "Missing connection string! Do you have " "CELERY_RESULT_DBURI set to a real value?")
def __init__(self, app=None, url=None, **kwargs): """Initialize MongoDB backend instance. :raises celery.exceptions.ImproperlyConfigured: if module :mod:`pymongo` is not available. """ self.options = {} super(MongoBackend, self).__init__(app, **kwargs) self.expires = kwargs.get('expires') or maybe_timedelta( self.app.conf.CELERY_TASK_RESULT_EXPIRES) if not pymongo: raise ImproperlyConfigured( 'You need to install the pymongo library to use the ' 'MongoDB backend.') config = self.app.conf.get('CELERY_MONGODB_BACKEND_SETTINGS') if config is not None: if not isinstance(config, dict): raise ImproperlyConfigured( 'MongoDB backend settings should be grouped in a dict') config = dict(config) # do not modify original self.host = config.pop('host', self.host) self.port = int(config.pop('port', self.port)) self.user = config.pop('user', self.user) self.password = config.pop('password', self.password) self.database_name = config.pop('database', self.database_name) self.taskmeta_collection = config.pop( 'taskmeta_collection', self.taskmeta_collection, ) self.options = dict(config, **config.pop('options', None) or {}) print self.options # Set option defaults #if pymongo.version_tuple >= (3, ): # self.options.setdefault('maxPoolSize', self.max_pool_size) #else: # self.options.setdefault('max_pool_size', self.max_pool_size) # self.options.setdefault('auto_start_request', False) self.url = url print url if self.url: # Specifying backend as an URL self.host = self.url
def __init__(self, *args, **kwargs): """Initialize MongoDB backend instance. :raises celery.exceptions.ImproperlyConfigured: if module :mod:`pymongo` is not available. """ self.options = {} super(MongoBackend, self).__init__(*args, **kwargs) self.expires = kwargs.get('expires') or maybe_timedelta( self.app.conf.CELERY_TASK_RESULT_EXPIRES) if not pymongo: raise ImproperlyConfigured( 'You need to install the pymongo library to use the ' 'MongoDB backend.') config = self.app.conf.get('CELERY_MONGODB_BACKEND_SETTINGS') if config is not None: if not isinstance(config, dict): raise ImproperlyConfigured( 'MongoDB backend settings should be grouped in a dict') config = dict(config) # do not modify original self.host = config.pop('host', self.host) self.port = int(config.pop('port', self.port)) self.user = config.pop('user', self.user) self.password = config.pop('password', self.password) self.database_name = config.pop('database', self.database_name) self.taskmeta_collection = config.pop( 'taskmeta_collection', self.taskmeta_collection, ) self.groupmeta_collection = config.pop( 'groupmeta_collection', self.groupmeta_collection, ) self.options = dict(config, **config.pop('options', None) or {}) # Set option defaults self.options.setdefault('max_pool_size', self.max_pool_size) self.options.setdefault('auto_start_request', False) url = kwargs.get('url') if url: # Specifying backend as an URL self.host = url
def __init__(self, app=None, url=None, **kwargs): """Initialize MongoDB backend instance. :raises celery.exceptions.ImproperlyConfigured: if module :mod:`pymongo` is not available. """ self.options = {} super(MongoBackend, self).__init__(app, **kwargs) self.expires = kwargs.get("expires") or maybe_timedelta(self.app.conf.CELERY_TASK_RESULT_EXPIRES) if not pymongo: raise ImproperlyConfigured("You need to install the pymongo library to use the " "MongoDB backend.") config = self.app.conf.get("CELERY_MONGODB_BACKEND_SETTINGS") if config is not None: if not isinstance(config, dict): raise ImproperlyConfigured("MongoDB backend settings should be grouped in a dict") config = dict(config) # do not modify original self.host = config.pop("host", self.host) self.port = int(config.pop("port", self.port)) self.user = config.pop("user", self.user) self.password = config.pop("password", self.password) self.database_name = config.pop("database", self.database_name) self.taskmeta_collection = config.pop("taskmeta_collection", self.taskmeta_collection) self.options = dict(config, **config.pop("options", None) or {}) print self.options # Set option defaults # if pymongo.version_tuple >= (3, ): # self.options.setdefault('maxPoolSize', self.max_pool_size) # else: # self.options.setdefault('max_pool_size', self.max_pool_size) # self.options.setdefault('auto_start_request', False) self.url = url print url if self.url: # Specifying backend as an URL self.host = self.url
def __init__(self, host=None, port=None, bucket_name=None, protocol=None, url=None, *args, **kwargs): """Initialize Riak backend instance. :raises celery.exceptions.ImproperlyConfigured: if module :mod:`riak` is not available. """ super(RiakBackend, self).__init__(*args, **kwargs) self.expires = kwargs.get('expires') or maybe_timedelta( self.app.conf.CELERY_TASK_RESULT_EXPIRES) if not riak: raise ImproperlyConfigured( 'You need to install the riak library to use the ' 'Riak backend.') uhost = uport = uname = upass = ubucket = None if url: uprot, uhost, uport, uname, upass, ubucket, _ = _parse_url(url) if ubucket: ubucket = ubucket.strip('/') config = self.app.conf.get('CELERY_RIAK_BACKEND_SETTINGS', None) if config is not None: if not isinstance(config, dict): raise ImproperlyConfigured( 'Riak backend settings should be grouped in a dict') else: config = {} self.host = uhost or config.get('host', self.host) self.port = int(uport or config.get('port', self.port)) self.bucket_name = ubucket or config.get('bucket', self.bucket_name) self.protocol = protocol or config.get('protocol', self.protocol) # riak bucket must be ascii letters or numbers only if not is_ascii(self.bucket_name): raise ValueError(E_BUCKET_NAME.format(self.bucket_name)) self._client = None
def __init__(self, url=None, *args, **kwargs): """Initialize CouchDB backend instance. :raises celery.exceptions.ImproperlyConfigured: if module :mod:`pycouchdb` is not available. """ super(CouchDBBackend, self).__init__(*args, **kwargs) self.expires = kwargs.get('expires') or maybe_timedelta( self.app.conf.CELERY_TASK_RESULT_EXPIRES) if pycouchdb is None: raise ImproperlyConfigured( 'You need to install the pycouchdb library to use the ' 'CouchDB backend.', ) uscheme = uhost = uport = uname = upass = ucontainer = None if url: _, uhost, uport, uname, upass, ucontainer , _ = _parse_url(url) # noqa ucontainer = ucontainer.strip('/') if ucontainer else None config = self.app.conf.get('CELERY_COUCHDB_BACKEND_SETTINGS', None) if config is not None: if not isinstance(config, dict): raise ImproperlyConfigured( 'CouchDB backend settings should be grouped in a dict', ) else: config = {} self.scheme = uscheme or config.get('scheme', self.scheme) self.host = uhost or config.get('host', self.host) self.port = int(uport or config.get('port', self.port)) self.container = ucontainer or config.get('container', self.container) self.username = uname or config.get('username', self.username) self.password = upass or config.get('password', self.password) self._connection = None
def __init__(self, dburi=None, expires=None, engine_options=None, **kwargs): super(DatabaseBackend, self).__init__(**kwargs) conf = self.app.conf self.expires = maybe_timedelta(self.prepare_expires(expires)) self.dburi = dburi or conf.CELERY_RESULT_DBURI self.engine_options = dict( engine_options or {}, **conf.CELERY_RESULT_ENGINE_OPTIONS or {}) self.short_lived_sessions = kwargs.get( 'short_lived_sessions', conf.CELERY_RESULT_DB_SHORT_LIVED_SESSIONS, ) tablenames = conf.CELERY_RESULT_DB_TABLENAMES or {} Task.__table__.name = tablenames.get('task', 'celery_taskmeta') TaskSet.__table__.name = tablenames.get('group', 'celery_tasksetmeta') if not self.dburi: raise ImproperlyConfigured( 'Missing connection string! Do you have ' 'CELERY_RESULT_DBURI set to a real value?')
def __init__(self, servers=None, keyspace=None, column_family=None, cassandra_options=None, **kwargs): """Initialize Cassandra backend. Raises :class:`celery.exceptions.ImproperlyConfigured` if the :setting:`CASSANDRA_SERVERS` setting is not set. """ super(CassandraBackend, self).__init__(**kwargs) self.logger = self.app.log.setup_logger( name="celery.backends.cassandra") self.result_expires = kwargs.get("result_expires") or \ maybe_timedelta( self.app.conf.CELERY_TASK_RESULT_EXPIRES) if not pycassa: raise ImproperlyConfigured( "You need to install the pycassa library to use the " "Cassandra backend. See http://github.com/vomjom/pycassa") self.servers = servers or \ self.app.conf.get("CASSANDRA_SERVERS", self.servers) self.keyspace = keyspace or \ self.app.conf.get("CASSANDRA_KEYSPACE", self.keyspace) self.column_family = column_family or \ self.app.conf.get("CASSANDRA_COLUMN_FAMILY", self.column_family) self.cassandra_options = dict(cassandra_options or {}, **self.app.conf.get("CASSANDRA_OPTIONS", {})) if not self.servers or not self.keyspace or not self.column_family: raise ImproperlyConfigured( "Cassandra backend not configured.") self._column_family = None
def __init__(self, app=None, url=None, **kwargs): self.options = {} super(MongoBackend, self).__init__(app, **kwargs) self.expires = kwargs.get('expires') or maybe_timedelta( self.app.conf.CELERY_TASK_RESULT_EXPIRES) if not pymongo: raise ImproperlyConfigured( 'You need to install the pymongo library to use the ' 'MongoDB backend.') config = self.app.conf.get('CELERY_MONGODB_BACKEND_SETTINGS') if config is not None: if not isinstance(config, dict): raise ImproperlyConfigured( 'MongoDB backend settings should be grouped in a dict') config = dict(config) # do not modify original self.host = config.pop('host', self.host) self.port = int(config.pop('port', self.port)) self.user = config.pop('user', self.user) self.password = config.pop('password', self.password) self.database_name = config.pop('database', self.database_name) self.taskmeta_collection = config.pop( 'taskmeta_collection', self.taskmeta_collection, ) self.options = dict(config, **config.pop('options', None) or {}) # Set option defaults for key, value in items(self._prepare_client_options()): self.options.setdefault(key, value) self.url = url if self.url: # Specifying backend as an URL self.host = self.url
def expired(self, states, expires, nowfun=now): return self.filter(state__in=states, tstamp__lte=nowfun() - maybe_timedelta(expires))
def get_all_expired(self, expires): """Get all expired task results.""" return self.filter(date_done__lt=now() - maybe_timedelta(expires))
def __init__(self, remaining): self._remaining = maybe_timedelta(remaining) self.run_every = timedelta(seconds=1) self.nowfun = datetime.utcnow
def cleanup(self): """Delete expired metadata.""" expires = maybe_timedelta(self.expires) for model in self.TaskModel, self.TaskSetModel: model._default_manager.delete_expired(expires)