From ce2b3ae849cd24369bf36edd8b6198dafa388438 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Fri, 27 Dec 2019 19:22:48 +0100 Subject: [PATCH] LINT fixes --- platypush/__init__.py | 2 +- platypush/backend/redis.py | 27 ++++++++++++--------------- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/platypush/__init__.py b/platypush/__init__.py index 9be53883..405abe6f 100644 --- a/platypush/__init__.py +++ b/platypush/__init__.py @@ -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', {})) diff --git a/platypush/backend/redis.py b/platypush/backend/redis.py index d53db81f..79feae85 100644 --- a/platypush/backend/redis.py +++ b/platypush/backend/redis.py @@ -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: -