forked from platypush/platypush
get_redis() should be a general utility method
This commit is contained in:
parent
a6c7d64511
commit
1f6c7aae60
4 changed files with 14 additions and 11 deletions
|
@ -11,8 +11,9 @@ from platypush.backend import Backend
|
||||||
from platypush.config import Config
|
from platypush.config import Config
|
||||||
from platypush.message.event.music import MusicPlayEvent, MusicPauseEvent, MusicStopEvent, \
|
from platypush.message.event.music import MusicPlayEvent, MusicPauseEvent, MusicStopEvent, \
|
||||||
NewPlayingTrackEvent, SeekChangeEvent, VolumeChangeEvent
|
NewPlayingTrackEvent, SeekChangeEvent, VolumeChangeEvent
|
||||||
|
from platypush.utils import get_redis
|
||||||
|
|
||||||
from .event import get_redis, status_queue
|
from .event import status_queue
|
||||||
|
|
||||||
|
|
||||||
class MusicSpotifyConnectBackend(Backend):
|
class MusicSpotifyConnectBackend(Backend):
|
||||||
|
@ -205,11 +206,11 @@ class MusicSpotifyConnectBackend(Backend):
|
||||||
redis = get_redis()
|
redis = get_redis()
|
||||||
|
|
||||||
while not self.should_stop():
|
while not self.should_stop():
|
||||||
msg = redis.get(parse=False)
|
msg = redis.blpop(status_queue, timeout=1)
|
||||||
if not msg:
|
if not msg:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
self._process_status_msg(json.loads(msg))
|
self._process_status_msg(json.loads(msg[1]))
|
||||||
|
|
||||||
return loop
|
return loop
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1 @@
|
||||||
from platypush.bus.redis import RedisBus
|
|
||||||
|
|
||||||
status_queue = 'platypush/music/spotify/connect/status'
|
status_queue = 'platypush/music/spotify/connect/status'
|
||||||
|
|
||||||
|
|
||||||
def get_redis() -> RedisBus:
|
|
||||||
return RedisBus(redis_queue=status_queue)
|
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from . import get_redis
|
from platypush.utils import get_redis
|
||||||
|
from . import status_queue
|
||||||
|
|
||||||
environ_variables = [
|
environ_variables = [
|
||||||
'PLAYER_EVENT',
|
'PLAYER_EVENT',
|
||||||
|
@ -14,7 +15,7 @@ environ_variables = [
|
||||||
|
|
||||||
|
|
||||||
def on_librespot_event():
|
def on_librespot_event():
|
||||||
get_redis().post(json.dumps({
|
get_redis().rpush(status_queue, json.dumps({
|
||||||
var: os.environ[var]
|
var: os.environ[var]
|
||||||
for var in environ_variables
|
for var in environ_variables
|
||||||
if var in os.environ
|
if var in os.environ
|
||||||
|
|
|
@ -12,6 +12,8 @@ import ssl
|
||||||
import urllib.request
|
import urllib.request
|
||||||
from typing import Optional, Tuple
|
from typing import Optional, Tuple
|
||||||
|
|
||||||
|
from redis import Redis
|
||||||
|
|
||||||
logger = logging.getLogger('utils')
|
logger = logging.getLogger('utils')
|
||||||
|
|
||||||
|
|
||||||
|
@ -438,4 +440,9 @@ def get_enabled_plugins() -> dict:
|
||||||
return plugins
|
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:
|
# vim:sw=4:ts=4:et:
|
||||||
|
|
Loading…
Reference in a new issue