diff --git a/src/backend/backend.py b/src/backend/backend.py index 6eccdd24..cf3c63b3 100644 --- a/src/backend/backend.py +++ b/src/backend/backend.py @@ -258,7 +258,8 @@ class Backend: while True: for client in self.clients.values(): - if client.syncing: + if client.healthy: + print( client, client.first_sync_done) return client if failures and failures % 300 == 0: diff --git a/src/backend/matrix_client.py b/src/backend/matrix_client.py index 24d5cd2e..9fda547b 100644 --- a/src/backend/matrix_client.py +++ b/src/backend/matrix_client.py @@ -189,8 +189,9 @@ class MatrixClient(nio.AsyncClient): self.upload_tasks: Dict[UUID, asyncio.Task] = {} self.send_message_tasks: Dict[UUID, asyncio.Task] = {} - self.first_sync_done: asyncio.Event = asyncio.Event() - self.first_sync_date: Optional[datetime] = None + self.first_sync_done: asyncio.Event = asyncio.Event() + self.first_sync_date: Optional[datetime] = None + self.last_sync_error: Optional[Exception] = None self.past_tokens: Dict[str, str] = {} # {room_id: token} self.fully_loaded_rooms: Set[str] = set() # {room_id} @@ -324,13 +325,15 @@ class MatrixClient(nio.AsyncClient): await self.close() @property - def syncing(self) -> bool: - """Return whether this client is currently syncing with the server.""" + def healthy(self) -> bool: + """Return whether we're syncing and last sync was successful.""" - if not self.sync_task: + task = self.sync_task + + if not task or not self.first_sync_date or self.last_sync_error: return False - return not self.sync_task.done() + return not task.done() async def _start(self) -> None: @@ -395,6 +398,8 @@ class MatrixClient(nio.AsyncClient): await self.sync_task break # task cancelled except Exception as err: + self.last_sync_error = err + trace = traceback.format_exc().rstrip() if isinstance(err, MatrixError) and err.http_code >= 500: @@ -405,6 +410,8 @@ class MatrixClient(nio.AsyncClient): ) else: LoopException(str(err), err, trace) + else: + self.last_sync_error = None await asyncio.sleep(5) diff --git a/src/icons/thin/image-rotate-left.svg b/src/icons/thin/image-rotate-left.svg new file mode 100644 index 00000000..634eee2e --- /dev/null +++ b/src/icons/thin/image-rotate-left.svg @@ -0,0 +1,3 @@ + + + diff --git a/src/icons/thin/image-rotate-right.svg b/src/icons/thin/image-rotate-right.svg new file mode 100644 index 00000000..07fa9321 --- /dev/null +++ b/src/icons/thin/image-rotate-right.svg @@ -0,0 +1,3 @@ + + +