get_redis() should be a general utility method

This commit is contained in:
Fabio Manganiello 2021-06-26 11:14:26 +02:00
parent a6c7d64511
commit 1f6c7aae60
4 changed files with 14 additions and 11 deletions

View file

@ -11,8 +11,9 @@ from platypush.backend import Backend
from platypush.config import Config
from platypush.message.event.music import MusicPlayEvent, MusicPauseEvent, MusicStopEvent, \
NewPlayingTrackEvent, SeekChangeEvent, VolumeChangeEvent
from platypush.utils import get_redis
from .event import get_redis, status_queue
from .event import status_queue
class MusicSpotifyConnectBackend(Backend):
@ -205,11 +206,11 @@ class MusicSpotifyConnectBackend(Backend):
redis = get_redis()
while not self.should_stop():
msg = redis.get(parse=False)
msg = redis.blpop(status_queue, timeout=1)
if not msg:
continue
self._process_status_msg(json.loads(msg))
self._process_status_msg(json.loads(msg[1]))
return loop

View file

@ -1,7 +1 @@
from platypush.bus.redis import RedisBus
status_queue = 'platypush/music/spotify/connect/status'
def get_redis() -> RedisBus:
return RedisBus(redis_queue=status_queue)

View file

@ -1,7 +1,8 @@
import json
import os
from . import get_redis
from platypush.utils import get_redis
from . import status_queue
environ_variables = [
'PLAYER_EVENT',
@ -14,7 +15,7 @@ environ_variables = [
def on_librespot_event():
get_redis().post(json.dumps({
get_redis().rpush(status_queue, json.dumps({
var: os.environ[var]
for var in environ_variables
if var in os.environ

View file

@ -12,6 +12,8 @@ import ssl
import urllib.request
from typing import Optional, Tuple
from redis import Redis
logger = logging.getLogger('utils')
@ -438,4 +440,9 @@ def get_enabled_plugins() -> dict:
return plugins
def get_redis() -> Redis:
from platypush.config import Config
return Redis(**(Config.get('backend.redis') or {}).get('redis_args', {}))
# vim:sw=4:ts=4:et: