예제 #1
0
파일: ws.py 프로젝트: m0g/superdesk-core
def create_server(config):
    """Create websocket server and run it until it gets Ctrl+C or SIGTERM.
    :param config: config dictionary
    """
    try:
        host = config['WS_HOST']
        port = int(config['WS_PORT'])
        broker_url = config['BROKER_URL']
        comms = SocketCommunication(host, port, broker_url)
        comms.run_server()
    except:
        logger.exception('Failed to start the WebSocket server.')
예제 #2
0
def create_server(config):
    """Create websocket server and run it until it gets Ctrl+C or SIGTERM.
    :param config: config dictionary
    """
    try:
        host = config['WS_HOST']
        port = int(config['WS_PORT'])
        broker_url = config['BROKER_URL']
        comms = SocketCommunication(host, port, broker_url)
        comms.run_server()
    except:
        logger.exception('Failed to start the WebSocket server.')
예제 #3
0
def create_server(config):
    """Create websocket server and run it until it gets Ctrl+C or SIGTERM.

    :param config: config dictionary
    """
    try:
        host = config["WS_HOST"]
        port = int(config["WS_PORT"])
        broker_url = config["BROKER_URL"]
        exchange_name = config.get("WEBSOCKET_EXCHANGE")
        comms = SocketCommunication(host, port, broker_url, exchange_name)
        comms.run_server()
    except Exception:
        logger.exception("Failed to start the WebSocket server.")
예제 #4
0
    def test_broadcast(self):
        loop = asyncio.new_event_loop()
        asyncio.set_event_loop(loop)
        client = TestClient()
        com = SocketCommunication('host', 'port', 'url')
        com.clients.add(client)

        loop.run_until_complete(com.broadcast(dumps({
            'event': 'ingest:update',
            '_created': datetime.now().isoformat()})))
        self.assertEqual(1, len(client.messages))

        loop.run_until_complete(com.broadcast(dumps({
            'event': 'ingest:update',
            '_created': datetime.now().isoformat()})))
        self.assertEqual(1, len(client.messages))

        loop.run_until_complete(com.broadcast(dumps({
            'event': 'foo',
            '_created': datetime.now().isoformat()})))
        self.assertEqual(2, len(client.messages))

        loop.run_until_complete(com.broadcast(dumps({
            'event': 'foo',
            '_created': datetime.now().isoformat()})))
        self.assertEqual(3, len(client.messages))

        loop.run_until_complete(com.broadcast(dumps({
            'event': 'ingest:update',
            '_created': (datetime.now() + timedelta(seconds=3600)).isoformat()})))
        self.assertEqual(4, len(client.messages))
예제 #5
0
    def test_broadcast(self):
        loop = asyncio.new_event_loop()
        asyncio.set_event_loop(loop)
        client = TestClient()
        com = SocketCommunication('host', 'port', 'url')
        com.clients.add(client)

        loop.run_until_complete(
            com.broadcast(
                dumps({
                    'event': 'ingest:update',
                    '_created': datetime.now().isoformat()
                })))
        self.assertEqual(1, len(client.messages))

        loop.run_until_complete(
            com.broadcast(
                dumps({
                    'event': 'ingest:update',
                    '_created': datetime.now().isoformat()
                })))
        self.assertEqual(1, len(client.messages))

        loop.run_until_complete(
            com.broadcast(
                dumps({
                    'event': 'foo',
                    '_created': datetime.now().isoformat()
                })))
        self.assertEqual(2, len(client.messages))

        loop.run_until_complete(
            com.broadcast(
                dumps({
                    'event': 'foo',
                    '_created': datetime.now().isoformat()
                })))
        self.assertEqual(3, len(client.messages))

        loop.run_until_complete(
            com.broadcast(
                dumps({
                    'event':
                    'ingest:update',
                    '_created':
                    (datetime.now() + timedelta(seconds=3600)).isoformat()
                })))
        self.assertEqual(4, len(client.messages))
예제 #6
0
    def test_broadcast(self):
        loop = asyncio.new_event_loop()
        asyncio.set_event_loop(loop)
        client = TestClient()
        com = SocketCommunication("host", "port", "url")
        com.clients.add(client)

        loop.run_until_complete(
            com.broadcast(
                dumps({
                    "event": "ingest:update",
                    "_created": datetime.now().isoformat()
                })))
        self.assertEqual(1, len(client.messages))

        loop.run_until_complete(
            com.broadcast(
                dumps({
                    "event": "ingest:update",
                    "_created": datetime.now().isoformat()
                })))
        self.assertEqual(1, len(client.messages))

        loop.run_until_complete(
            com.broadcast(
                dumps({
                    "event": "foo",
                    "_created": datetime.now().isoformat()
                })))
        self.assertEqual(2, len(client.messages))

        loop.run_until_complete(
            com.broadcast(
                dumps({
                    "event": "foo",
                    "_created": datetime.now().isoformat()
                })))
        self.assertEqual(3, len(client.messages))

        loop.run_until_complete(
            com.broadcast(
                dumps({
                    "event":
                    "ingest:update",
                    "_created":
                    (datetime.now() + timedelta(seconds=3600)).isoformat()
                })))
        self.assertEqual(4, len(client.messages))