Get Redis object on each interaction in case the backend wasn't ready before

This commit is contained in:
Fabio Manganiello 2018-07-08 22:12:30 +02:00
parent e1ead3c25f
commit c81534875a

View file

@ -141,7 +141,8 @@ class HttpBackend(Backend):
stop_evt = StopEvent(target=self.device_id, origin=self.device_id, stop_evt = StopEvent(target=self.device_id, origin=self.device_id,
thread_id=self.redis_thread.ident) 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: if self.server_proc:
self.server_proc.terminate() self.server_proc.terminate()
@ -167,7 +168,8 @@ class HttpBackend(Backend):
""" Polls for new messages on the internal Redis queue """ """ Polls for new messages on the internal Redis queue """
while True: 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'))) msg = Message.build(json.loads(msg[1].decode('utf-8')))
if isinstance(msg, StopEvent) and \ if isinstance(msg, StopEvent) and \
@ -240,7 +242,8 @@ class HttpBackend(Backend):
self.logger.info('Processing response on the HTTP backend: {}'.format(msg)) self.logger.info('Processing response on the HTTP backend: {}'.format(msg))
return str(response) return str(response)
elif isinstance(msg, Event): 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' }) return jsonify({ 'status': 'ok' })
@ -272,7 +275,8 @@ class HttpBackend(Backend):
event = WidgetUpdateEvent( event = WidgetUpdateEvent(
widget=widget, **(json.loads(http_request.data.decode('utf-8')))) 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' }) return jsonify({ 'status': 'ok' })
@app.route('/static/<path>', methods=['GET']) @app.route('/static/<path>', methods=['GET'])