steam-server/app/tasks/cleanup_task.py

18 lines
594 B
Python
Raw Normal View History

2024-12-12 20:04:36 +08:00
# 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
logger = get_logger(__name__)
async def cleanup_streams():
while True:
await asyncio.sleep(60)
now = int(time.time() * 1000)
logger.info("定时任务执行:清理空闲流")
for stream_id, stream in list(stream_manager.items()):
if now - stream["create_time"] > 60 * 1000 * 1:
stop_stream(stream_id)
logger.info(f"清理空闲流:{stream_id}")