try not to break

This commit is contained in:
Benedetta 2024-04-09 18:37:18 +02:00
parent e3efdad3de
commit 810044e134

View file

@ -27,10 +27,12 @@ async def matrixmain(matrix_client: matrix.MatrixClient, mq_client: mq.MQClient,
client.add_event_callback(callback, RoomMessageText) client.add_event_callback(callback, RoomMessageText)
while True:
try: try:
await client.sync_forever(timeout=30000, full_state=True) # milliseconds await client.sync_forever(timeout=30000, full_state=True) # milliseconds
log.info('exiting from the matrix loop') log.info('exiting from the matrix loop')
client.logout() client.logout()
break
except Exception as e: except Exception as e:
log.error(f'exception in matrix loop: {e}') log.error(f'exception in matrix loop: {e}')
@ -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 with rabbit_client.queue.iterator() as queue_iter:
async for message in queue_iter: async for message in queue_iter:
async with message.process(): async with message.process():
try:
body = message.body.decode() body = message.body.decode()
br = protocol.json_to_bot_response(body) br = protocol.json_to_bot_response(body)
# logging.info(f'New message from MQ: {str(br)[:24]}...') # logging.info(f'New message from MQ: {str(br)[:24]}...')
await matrix.send_text(matrix_client, br) await matrix.send_text(matrix_client, br)
except Exception as e:
print(e)
log.error(f'exception in mq loop: {e}')
try: try:
async with rabbit_client.connection: async with rabbit_client.connection: