def __init__(self, backend=None, **kwargs): self._loop = asyncio.get_event_loop() if backend == 'mongo': self.backend = MongoBackend(**kwargs) elif backend == 'memory': self.backend = MemoryBackend(**kwargs) else: raise PersistenceError
def __init__(self, backend=None, memory_size=None, loop=None, **kwargs): """ TODO: mongo is the only one yet, we should parse available modules named `*_backend.py` and select after the given backend. """ self._loop = loop or asyncio.get_event_loop() self._last_events = FIFOSizedQueue(memory_size or 10000) self.backend = None self._feed_future = None if not backend: log.info('No persistence backend selected, in-memory only') return if backend != 'mongo': raise ValueError("'mongo' is the only available backend") self.backend = MongoBackend(**kwargs) if not isinstance(self.backend, PersistenceBackend): raise PersistenceError( 'Wrong backend selected: {}'.format(backend)) self._feed_future = asyncio.ensure_future(self._feed_backend())