async def get_slack_events(): if scribereader is None: logging.error("Scribereader unavailable. Not tailing slack events.") return host_and_port = scribereader.get_env_scribe_host(SCRIBE_ENV, True) host = host_and_port["host"] port = host_and_port["port"] while True: reader, writer = await asyncio.open_connection(host=host, port=port) writer.write( construct_conn_msg(stream=SLACK_WEBHOOK_STREAM).encode("utf-8")) await writer.drain() while True: line = await reader.readline() log.debug(f"got log line {line.decode('utf-8')}") if not line: break event = parse_webhook_event_json(line) if is_relevant_event(event): yield event log.warning("Lost connection to scribe host; reconnecting")
def test_tail_lines_with_options(): conn_msg = readers.construct_conn_msg( 'streamA', protocol_opts={'opt1': 'value1', 'opt2': 'value2'}) assert conn_msg.startswith('streamA opt') assert conn_msg.endswith('\n') assert ' opt1=value1' in conn_msg assert ' opt2=value2' in conn_msg assert len(conn_msg) == 32
def test_tail_lines_with_options(): conn_msg = readers.construct_conn_msg('streamA', protocol_opts={ 'opt1': 'value1', 'opt2': 'value2' }) assert conn_msg.startswith('streamA opt') assert conn_msg.endswith('\n') assert ' opt1=value1' in conn_msg assert ' opt2=value2' in conn_msg assert len(conn_msg) == 32
def test_construct_conn_msg_with_lines(): conn_msg = readers.construct_conn_msg('streamA', lines=2) assert conn_msg == 'streamA 2\n'
def test_construct_conn_msg_without_lines(): conn_msg = readers.construct_conn_msg("streamA") assert conn_msg == 'streamA\n'