Skip to content

Commit ffc011b

Browse files
committed
feat: limit concurrent stream info fetch per platform using asyncio.Semaphore
1 parent 39a3ccf commit ffc011b

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

app/core/record_manager.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import asyncio
22
import threading
3+
from collections import defaultdict
34
from datetime import datetime, timedelta
45

56
from ..messages.message_pusher import MessagePusher
@@ -27,6 +28,7 @@ def __init__(self, app):
2728
self._ = {}
2829
self.load()
2930
self.initialize_dynamic_state()
31+
self.platform_semaphores = defaultdict(lambda: asyncio.Semaphore(3))
3032

3133
@property
3234
def recordings(self):
@@ -248,9 +250,11 @@ async def check_if_live(self, recording: Recording):
248250
"quality": recording.quality,
249251
}
250252

253+
semaphore = self.platform_semaphores[platform_key]
251254
recorder = LiveStreamRecorder(self.app, recording, recording_info)
252-
stream_info = await recorder.fetch_stream()
253-
logger.info(f"Stream Data: {stream_info}")
255+
async with semaphore:
256+
stream_info = await recorder.fetch_stream()
257+
logger.info(f"Stream Data: {stream_info}")
254258
if not stream_info or not stream_info.anchor_name:
255259
logger.error(f"Fetch stream data failed: {recording.url}")
256260
recording.is_checking = False

0 commit comments

Comments
 (0)