steam-server/app/tasks/cleanup_task.py
2024-12-16 14:31:28 +08:00

20 lines
697 B
Python

# app/tasks/cleanup_task.py
import asyncio
import time
from app.services.stream_manager import stream_manager, stop_stream
from app.utils.logger import get_logger
from app.config import expired_timeout, cleanup_interval
logger = get_logger(__name__)
async def cleanup_streams():
while True:
await asyncio.sleep(cleanup_interval)
now = int(time.time() * 1000)
logger.info("定时任务执行:清理空闲流")
print(stream_manager)
for stream_id, stream in list(stream_manager.items()):
if now - stream["create_time"] > expired_timeout:
stop_stream(stream_id)
logger.info(f"清理空闲流:{stream_id}")