diff --git a/lanonna/lanonna.py b/lanonna/lanonna.py index c11ef91..fb74229 100644 --- a/lanonna/lanonna.py +++ b/lanonna/lanonna.py @@ -27,12 +27,14 @@ async def matrixmain(matrix_client: matrix.MatrixClient, mq_client: mq.MQClient, client.add_event_callback(callback, RoomMessageText) - try: - await client.sync_forever(timeout=30000, full_state=True) # milliseconds - log.info('exiting from the matrix loop') - client.logout() - except Exception as e: - log.error(f'exception in matrix loop: {e}') + while True: + try: + await client.sync_forever(timeout=30000, full_state=True) # milliseconds + log.info('exiting from the matrix loop') + client.logout() + break + except Exception as e: + log.error(f'exception in matrix loop: {e}') async def mqmain(rabbit_client: mq.MQClient, matrix_client: matrix.MatrixClient): @@ -40,10 +42,14 @@ async def mqmain(rabbit_client: mq.MQClient, matrix_client: matrix.MatrixClient) async with rabbit_client.queue.iterator() as queue_iter: async for message in queue_iter: async with message.process(): - body = message.body.decode() - br = protocol.json_to_bot_response(body) - # logging.info(f'New message from MQ: {str(br)[:24]}...') - await matrix.send_text(matrix_client, br) + try: + body = message.body.decode() + br = protocol.json_to_bot_response(body) + # logging.info(f'New message from MQ: {str(br)[:24]}...') + await matrix.send_text(matrix_client, br) + except Exception as e: + print(e) + log.error(f'exception in mq loop: {e}') try: async with rabbit_client.connection: