From 13e08094e5e6f3fe8fd1449f0167958ac265d264 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A9=AC=E7=89=B9=E6=B5=A9=E5=80=AA?= Date: Wed, 31 Jan 2024 10:02:46 +0800 Subject: [PATCH] add info after broadcast --- service/backend/app/utils/activitypub_protocol.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/service/backend/app/utils/activitypub_protocol.py b/service/backend/app/utils/activitypub_protocol.py index dc6de03..57ddccf 100644 --- a/service/backend/app/utils/activitypub_protocol.py +++ b/service/backend/app/utils/activitypub_protocol.py @@ -22,6 +22,7 @@ import aiohttp import certifi import ssl +import arrow from urllib.parse import urlparse from typing import Tuple, Type, Optional from fastapi.responses import JSONResponse @@ -312,6 +313,7 @@ async def broadcast(self) -> bool: 'No active subscribers found. Incoming activity will not be broadcasted') return False tasks = [] + start_time = arrow.now() for subscriber in subscribers: task = asyncio.create_task( self.send_msg(payload, subscriber.inbox) @@ -319,6 +321,17 @@ async def broadcast(self) -> bool: tasks.append(task) responses = await asyncio.gather(*tasks, return_exceptions=True) + end_time = arrow.now() + last = (end_time - start_time).seconds + s = 0 + f = 0 + for r in responses: + if isinstance(r, Exception): + f = f + 1 + else: + s = s+1 + logger.info( + f'Finish broadcast in {last}s, to {len(responses)} subscribers, {f} failures, {s} successes.') return True