forked from platypush/platypush
Using Redis backend as a fallback for send_message if a backend does not implement its own send_message
This commit is contained in:
parent
061b676fbc
commit
bd18d1cbc1
2 changed files with 15 additions and 7 deletions
|
@ -7,6 +7,7 @@ from threading import Thread
|
|||
|
||||
from platypush.bus import Bus
|
||||
from platypush.config import Config
|
||||
from platypush.context import get_backend
|
||||
from platypush.utils import get_message_class_by_type, set_timeout, clear_timeout
|
||||
from platypush.message import Message
|
||||
from platypush.message.event import Event, StopEvent
|
||||
|
@ -186,13 +187,21 @@ class Backend(Thread):
|
|||
def send_message(self, msg, **kwargs):
|
||||
"""
|
||||
Sends a platypush.message.Message to a node.
|
||||
To be implemented in the derived classes.
|
||||
Always call send_request or send_response instead of send_message directly
|
||||
To be implemented in the derived classes. By default, if the Redis
|
||||
backend is configured then it will try to deliver the message to
|
||||
other consumers through the configured Redis main queue.
|
||||
|
||||
Param:
|
||||
msg -- The message
|
||||
"""
|
||||
pass
|
||||
try:
|
||||
redis = get_backend('redis')
|
||||
except KeyError:
|
||||
self.logger.warning("Backend {} does not implement send_message " +
|
||||
"and the fallback Redis backend isn't configured")
|
||||
return
|
||||
|
||||
redis.send_message(msg)
|
||||
|
||||
|
||||
def run(self):
|
||||
|
|
|
@ -10,7 +10,6 @@ import urllib.parse
|
|||
from dbus.exceptions import DBusException
|
||||
from omxplayer import OMXPlayer
|
||||
|
||||
from platypush.context import get_bus
|
||||
from platypush.plugins.media import PlayerState
|
||||
from platypush.message.response import Response
|
||||
from platypush.message.event.video import VideoPlayEvent, VideoPauseEvent, \
|
||||
|
@ -198,17 +197,17 @@ class VideoOmxplayerPlugin(Plugin):
|
|||
|
||||
def on_play(self):
|
||||
def _f(player):
|
||||
get_bus().post(VideoPlayEvent(video=self.player.get_source()))
|
||||
self.send_message(VideoPlayEvent(video=self.player.get_source()))
|
||||
return _f
|
||||
|
||||
def on_pause(self):
|
||||
def _f(player):
|
||||
get_bus().post(VideoPauseEvent(video=self.player.get_source()))
|
||||
self.send_message(VideoPauseEvent(video=self.player.get_source()))
|
||||
return _f
|
||||
|
||||
def on_stop(self):
|
||||
def _f(player):
|
||||
get_bus().post(VideoStopEvent())
|
||||
self.send_message(VideoStopEvent())
|
||||
return _f
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue