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.')
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.")
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))
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))
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))