From c81534875af460396d1461ef16ee62032fa80ce3 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Sun, 8 Jul 2018 22:12:30 +0200 Subject: [PATCH] Get Redis object on each interaction in case the backend wasn't ready before --- platypush/backend/http/__init__.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/platypush/backend/http/__init__.py b/platypush/backend/http/__init__.py index 4b77ccd71..1a52c4528 100644 --- a/platypush/backend/http/__init__.py +++ b/platypush/backend/http/__init__.py @@ -141,7 +141,8 @@ class HttpBackend(Backend): stop_evt = StopEvent(target=self.device_id, origin=self.device_id, thread_id=self.redis_thread.ident) - self.redis.rpush(self.redis_queue, stop_evt) + redis = self._get_redis() + redis.rpush(self.redis_queue, stop_evt) if self.server_proc: self.server_proc.terminate() @@ -167,7 +168,8 @@ class HttpBackend(Backend): """ Polls for new messages on the internal Redis queue """ while True: - msg = self.redis.blpop(self.redis_queue) + redis = self._get_redis() + msg = redis.blpop(self.redis_queue) msg = Message.build(json.loads(msg[1].decode('utf-8'))) if isinstance(msg, StopEvent) and \ @@ -240,7 +242,8 @@ class HttpBackend(Backend): self.logger.info('Processing response on the HTTP backend: {}'.format(msg)) return str(response) elif isinstance(msg, Event): - self.redis.rpush(self.redis_queue, msg) + redis = self._get_redis() + redis.rpush(self.redis_queue, msg) return jsonify({ 'status': 'ok' }) @@ -272,7 +275,8 @@ class HttpBackend(Backend): event = WidgetUpdateEvent( widget=widget, **(json.loads(http_request.data.decode('utf-8')))) - self.redis.rpush(self.redis_queue, event) + redis = self._get_redis() + redis.rpush(self.redis_queue, event) return jsonify({ 'status': 'ok' }) @app.route('/static/', methods=['GET'])