Skip to content

Commit

Permalink
add info after broadcast
Browse files Browse the repository at this point in the history
  • Loading branch information
mattholy committed Jan 31, 2024
1 parent 532c84b commit 13e0809
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions service/backend/app/utils/activitypub_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -312,13 +313,25 @@ 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)
)
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

Expand Down

0 comments on commit 13e0809

Please sign in to comment.