LINT fixes

This commit is contained in:
Fabio Manganiello 2019-12-27 19:22:48 +01:00
parent 5ba18ea7d5
commit ce2b3ae849
2 changed files with 13 additions and 16 deletions

View file

@ -163,7 +163,7 @@ class Daemon:
print('---- Starting platypush v.{}'.format(__version__))
redis_conf = Config.get('backend.redis', {})
redis_conf = Config.get('backend.redis') or {}
self.bus = RedisBus(on_message=self.on_message(),
**redis_conf.get('redis_args', {}))

View file

@ -19,39 +19,38 @@ class RedisBackend(Backend):
* **redis** (``pip install redis``)
"""
def __init__(self, queue='platypush_bus_mq', redis_args={}, *args, **kwargs):
def __init__(self, queue='platypush_bus_mq', redis_args=None, *args, **kwargs):
"""
:param queue: Queue name to listen on (default: ``platypush_bus_mq``)
:type queue: str
:param redis_args: Arguments that will be passed to the redis-py constructor (e.g. host, port, password), see http://redis-py.readthedocs.io/en/latest/
:param redis_args: Arguments that will be passed to the redis-py constructor (e.g. host, port, password), see
http://redis-py.readthedocs.io/en/latest/
:type redis_args: dict
"""
super().__init__(*args, **kwargs)
if redis_args is None:
redis_args = {}
self.queue = queue
self.redis_args = redis_args
if not redis_args:
try:
redis_plugin = get_plugin('redis')
if redis_plugin and redis_plugin.kwargs:
self.redis_args = redis_plugin.kwargs
except:
pass
redis_plugin = get_plugin('redis')
if redis_plugin and redis_plugin.kwargs:
redis_args = redis_plugin.kwargs
self.redis_args = redis_args
self.redis = Redis(**self.redis_args)
def send_message(self, msg, queue_name=None):
def send_message(self, msg, queue_name=None, **kwargs):
msg = str(msg)
if queue_name:
self.redis.rpush(queue_name, msg)
else:
self.redis.rpush(self.queue, msg)
# noinspection PyBroadException
def get_message(self, queue_name=None):
queue = queue_name or self.queue
msg = self.redis.blpop(queue)[1].decode('utf-8')
@ -70,12 +69,11 @@ class RedisBackend(Backend):
return msg
def run(self):
super().run()
self.logger.info('Initialized Redis backend on queue {} with arguments {}'.
format(self.queue, self.redis_args))
format(self.queue, self.redis_args))
while not self.should_stop():
try:
@ -88,4 +86,3 @@ class RedisBackend(Backend):
# vim:sw=4:ts=4:et: