refactor(transcode): thread fs ops + atomic cache publish
- run blocking Path.exists/read_text off the event loop via anyio.to_thread - publish HLS renditions by building into a temp dir then atomic rename, so a reader never sees a playlist referencing half-written segments - per-writer temp name for opus so two concurrent jobs can't interleave - drop a track's cached renditions on delete so they don't dangle Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -10,6 +10,7 @@ import re
|
||||
import uuid
|
||||
from typing import Annotated
|
||||
|
||||
import anyio
|
||||
from fastapi import APIRouter, Header, Query, Response
|
||||
from fastapi.responses import FileResponse, StreamingResponse
|
||||
|
||||
@@ -78,7 +79,7 @@ async def stream_hls_playlist(
|
||||
await enqueue_transcode_quiet(track_id, hls=True)
|
||||
raise NotFoundError("HLS rendition is being prepared; retry shortly.")
|
||||
|
||||
body = path.read_text()
|
||||
body = await anyio.to_thread.run_sync(path.read_text)
|
||||
if token:
|
||||
body = _SEGMENT_LINE_RE.sub(rf"\1?token={token}", body)
|
||||
return Response(body, media_type=_HLS_PLAYLIST_TYPE)
|
||||
|
||||
Reference in New Issue
Block a user