chore(storage): bound build retention, caches and test resources
Track build ownership, qualified pins and bounded cache/log lifecycles. Move Vite fixtures to a job-owned server helper and preserve private outputs outside Git.
This commit is contained in:
@@ -8,6 +8,7 @@ import shutil
|
||||
import threading
|
||||
from pathlib import Path
|
||||
|
||||
from k1link.cache_budget import cache_publication
|
||||
from k1link.simulation.ai_polygon.plans import PlanStore
|
||||
from k1link.simulation.ai_polygon.worlds import write_json
|
||||
|
||||
@@ -75,7 +76,8 @@ class EditorCache:
|
||||
else:
|
||||
if shutil.disk_usage(self.root).free < LIMIT + 512 * 1024**2:
|
||||
raise ValueError("Недостаточно места для локальной копии сцены.")
|
||||
path.mkdir(mode=0o700, exist_ok=True)
|
||||
with cache_publication(self.root, 65536, kind="editor-cache", max_files=4096):
|
||||
path.mkdir(mode=0o700, exist_ok=True)
|
||||
row = {
|
||||
"key": key,
|
||||
"identity": identity,
|
||||
@@ -85,9 +87,13 @@ class EditorCache:
|
||||
"error": None,
|
||||
}
|
||||
if world.get("local_scene"):
|
||||
row.update(status="ready", files=self.worlds.projects.cache_files(world),
|
||||
local_scene=world["local_scene"])
|
||||
write_json(path / "manifest.json", row)
|
||||
row.update(
|
||||
status="ready",
|
||||
files=self.worlds.projects.cache_files(world),
|
||||
local_scene=world["local_scene"],
|
||||
)
|
||||
with cache_publication(self.root, 65536, kind="editor-cache", max_files=4096):
|
||||
write_json(path / "manifest.json", row)
|
||||
return row
|
||||
|
||||
def pending(self):
|
||||
@@ -137,7 +143,20 @@ class EditorCache:
|
||||
and files["collision.glb"]["sha256"] != row["identity"]["collider_sha256"]
|
||||
):
|
||||
raise ValueError("Collider identity mismatch")
|
||||
row.update(files=files, status="uploading")
|
||||
# Reserve all declared remaining transfers in the existing manifests.
|
||||
# No extra reservation files or abandoned-expiry deletion are needed.
|
||||
remaining = sum(a["byte_length"] for a in files.values()) - sum(
|
||||
a.get("uploaded_bytes", 0) for a in row.get("files", {}).values()
|
||||
)
|
||||
with cache_publication(
|
||||
self.root,
|
||||
self._pending_bytes(exclude=key) + remaining + 65536,
|
||||
kind="editor-cache",
|
||||
max_files=4096,
|
||||
):
|
||||
row.update(files=files, status="uploading")
|
||||
write_json(path / "manifest.json", row)
|
||||
return self.get(key)
|
||||
elif action == "chunk":
|
||||
name = body.get("name")
|
||||
if name not in FILES or name not in row["files"] or row["status"] != "uploading":
|
||||
@@ -154,7 +173,15 @@ class EditorCache:
|
||||
raise ValueError("Invalid editor chunk")
|
||||
if shutil.disk_usage(path).free < len(payload) + 512 * 1024**2:
|
||||
raise ValueError("Недостаточно места для сцены.")
|
||||
with (path / (name + ".part")).open("ab") as stream:
|
||||
with (
|
||||
cache_publication(
|
||||
self.root,
|
||||
self._pending_bytes() + 65536,
|
||||
kind="editor-cache",
|
||||
max_files=4096,
|
||||
),
|
||||
(path / (name + ".part")).open("ab") as stream,
|
||||
):
|
||||
stream.write(payload)
|
||||
elif action == "complete":
|
||||
for name, asset in row["files"].items():
|
||||
@@ -180,6 +207,20 @@ class EditorCache:
|
||||
write_json(path / "manifest.json", row)
|
||||
return self.get(key)
|
||||
|
||||
def _pending_bytes(self, exclude=None):
|
||||
remaining = 0
|
||||
for manifest in self.root.glob("*/manifest.json"):
|
||||
if manifest.parent.name == exclude:
|
||||
continue
|
||||
row = self.get(manifest.parent.name)
|
||||
if row.get("local_scene") or row["status"] not in {"queued", "preparing", "uploading"}:
|
||||
continue
|
||||
remaining += sum(
|
||||
max(0, a["byte_length"] - a.get("uploaded_bytes", 0))
|
||||
for a in row.get("files", {}).values()
|
||||
)
|
||||
return remaining
|
||||
|
||||
def asset(self, key, name):
|
||||
row = self.get(key)
|
||||
if row["status"] != "ready" or name not in FILES:
|
||||
|
||||
Reference in New Issue
Block a user