Exemple #1
0
 def setUp(self):
     super(SockJSSubscriberTestCase, self).setUp()
     self.publisher = self._new_client()
     self.subscriber = SockJSSubscriber(self.client)
from tornado.web import StaticFileHandler, FallbackHandler, RedirectHandler,\
    Application
from tornado.wsgi import WSGIContainer
from sockjs.tornado import SockJSConnection, SockJSRouter
from tornadoredis import Client as RedisClient
from tornadoredis.pubsub import SockJSSubscriber

from .. import config
toolname = config.toolname
from .oauth_handler import app as oauth_wsgi  # noqa
from ..celery import app as celery_app  # noqa

# Create the tornadoredis.Client instance
# and use it for redis channel subscriptions
subscriber = SockJSSubscriber(
    RedisClient(host=config.redis_server,
                port=config.redis_port,
                selected_db=config.redis_db))


class SockConnection(SockJSConnection):
    def on_open(self, info):
        self.channel = str(uuid4())
        subscriber.subscribe(self.channel, self)

    def on_close(self):
        subscriber.unsubscribe(self.channel, self)

    def on_message(self, message):
        data = json.loads(message)
        data['redis_channel'] = self.channel
        if data['action'] == 'watchlist':