From ded551d1b3205c413fdad7f5d7fc7bd2e7757469 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Tue, 10 Nov 2020 00:40:01 +0200 Subject: [PATCH] Retry sending messages if server returns 502 --- mautrix_amp/config.py | 6 ++---- mautrix_amp/portal.py | 5 +++-- requirements.txt | 2 +- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/mautrix_amp/config.py b/mautrix_amp/config.py index 1b32ee6..5f09a8a 100644 --- a/mautrix_amp/config.py +++ b/mautrix_amp/config.py @@ -16,10 +16,8 @@ from typing import Any, List, NamedTuple import os -from mautrix.types import UserID -from mautrix.client import Client -from mautrix.bridge.config import (BaseBridgeConfig, ConfigUpdateHelper, ForbiddenKey, - ForbiddenDefault) +from mautrix.util.config import ConfigUpdateHelper, ForbiddenDefault +from mautrix.bridge.config import BaseBridgeConfig Permissions = NamedTuple("Permissions", user=bool, admin=bool, level=str) diff --git a/mautrix_amp/portal.py b/mautrix_amp/portal.py index 107f39a..ce0b751 100644 --- a/mautrix_amp/portal.py +++ b/mautrix_amp/portal.py @@ -26,6 +26,7 @@ from mautrix.types import (EventID, MessageEventContent, RoomID, EventType, Mess ContentURI, EncryptedFile) from mautrix.errors import MatrixError from mautrix.util.simple_lock import SimpleLock +from mautrix.util.network_retry import call_with_net_retry from .db import Portal as DBPortal, Message as DBMessage from .config import Config @@ -185,8 +186,8 @@ class Portal(DBPortal, BasePortal): upload_mime_type = "application/octet-stream" upload_file_name = None - mxc = await intent.upload_media(data, mime_type=upload_mime_type, - filename=upload_file_name) + mxc = await call_with_net_retry(intent.upload_media, data, mime_type=upload_mime_type, + filename=upload_file_name, _action="upload media") if decryption_info: decryption_info.url = mxc diff --git a/requirements.txt b/requirements.txt index 7991500..5bea549 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,7 +4,7 @@ commonmark>=0.8,<0.10 aiohttp>=3,<4 yarl>=1,<2 attrs>=19.1 -mautrix==0.8.0rc4 +mautrix>=0.8.2,<0.9 asyncpg>=0.20,<0.22 pillow>=4,<8 qrcode>=6,<7