Restart sync if exception occurs

This commit is contained in:
miruka 2019-10-30 11:10:40 -04:00
parent ce2a7f1018
commit b9fbd36661
2 changed files with 14 additions and 15 deletions

View File

@ -2,12 +2,12 @@
- Caching - Caching
- What effect will it have on GIFs? Can we set `cache:false` on them or get - What effect will it have on GIFs? Can we set `cache:false` on them or get
the frame count once they're cached? the frame count once they're cached?
- Reading encrypted media
- Uploading progress (+local echo)
- Deduplicate uploads
- Loading progress bar
- Downloading - Downloading
- Bottom/top bar - Bottom/top bar
- Uploading (+local echo)
- Deduplicate uploads
- Encrypted media
- Loading progress bar
- Support m.file thumbnails - Support m.file thumbnails
- Generate video thumbnails - Generate video thumbnails
@ -36,7 +36,6 @@
- When qml syntax highlighting supports ES6 string interpolation, use that - When qml syntax highlighting supports ES6 string interpolation, use that
- Fixes - Fixes
- Restart sync is exception occurs
- In the "Leave me" room, "join > Hi > left" aren't combined - In the "Leave me" room, "join > Hi > left" aren't combined
- Event delegates changing height don't scroll the list - Event delegates changing height don't scroll the list
- When selecting text and scrolling up, selection stops working after a while - When selecting text and scrolling up, selection stops working after a while

View File

@ -5,6 +5,7 @@ import io
import json import json
import logging as log import logging as log
import platform import platform
import traceback
from contextlib import suppress from contextlib import suppress
from dataclasses import dataclass from dataclasses import dataclass
from datetime import datetime from datetime import datetime
@ -139,13 +140,13 @@ class MatrixClient(nio.AsyncClient):
if isinstance(response, nio.LoginError): if isinstance(response, nio.LoginError):
raise RuntimeError(response) raise RuntimeError(response)
else: else:
await self.start() asyncio.ensure_future(self.start())
async def resume(self, user_id: str, token: str, device_id: str) -> None: async def resume(self, user_id: str, token: str, device_id: str) -> None:
response = nio.LoginResponse(user_id, device_id, token) response = nio.LoginResponse(user_id, device_id, token)
await self.receive_response(response) await self.receive_response(response)
await self.start() asyncio.ensure_future(self.start())
async def logout(self) -> None: async def logout(self) -> None:
@ -170,14 +171,13 @@ class MatrixClient(nio.AsyncClient):
ft = asyncio.ensure_future(self.backend.get_profile(self.user_id)) ft = asyncio.ensure_future(self.backend.get_profile(self.user_id))
ft.add_done_callback(on_profile_response) ft.add_done_callback(on_profile_response)
def on_sync_stop(future) -> None: while True:
if isinstance(future.exception(), BaseException): try:
raise future.exception() await self.sync_forever(timeout=10_000)
except Exception:
self.sync_task = asyncio.ensure_future( trace = traceback.format_exc().rstrip()
self.sync_forever(timeout=10_000), log.error("Exception during sync, will restart:\n%s", trace)
) await asyncio.sleep(2)
self.sync_task.add_done_callback(on_sync_stop)
@property @property