19 lines
667 B
Python
19 lines
667 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("定时任务执行:清理空闲流")
|
|
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}")
|