chore: snapshot workflow migration progress
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
from app.config import settings
|
||||
|
||||
|
||||
def asset_library_dir() -> Path:
|
||||
return Path(settings.upload_dir) / "asset-libraries"
|
||||
|
||||
|
||||
def list_asset_library_blends() -> list[Path]:
|
||||
directory = asset_library_dir()
|
||||
if not directory.is_dir():
|
||||
return []
|
||||
|
||||
return sorted(
|
||||
(path for path in directory.glob("*.blend") if path.is_file()),
|
||||
key=lambda path: (path.stat().st_mtime, path.name),
|
||||
reverse=True,
|
||||
)
|
||||
|
||||
|
||||
def resolve_asset_library_blend_path(
|
||||
*,
|
||||
blend_file_path: str | None = None,
|
||||
asset_library_id: Any | None = None,
|
||||
) -> str | None:
|
||||
"""Resolve the best available .blend path for an asset library.
|
||||
|
||||
Resolution order:
|
||||
1. explicit configured path, when it exists
|
||||
2. canonical uploads/asset-libraries/<id>.blend path
|
||||
3. newest available .blend under uploads/asset-libraries
|
||||
"""
|
||||
if blend_file_path:
|
||||
configured = Path(blend_file_path)
|
||||
if configured.is_file():
|
||||
return str(configured)
|
||||
|
||||
if asset_library_id:
|
||||
candidate = asset_library_dir() / f"{asset_library_id}.blend"
|
||||
if candidate.is_file():
|
||||
return str(candidate)
|
||||
|
||||
available = list_asset_library_blends()
|
||||
if available:
|
||||
return str(available[0])
|
||||
|
||||
return None
|
||||
@@ -8,6 +8,7 @@ import subprocess
|
||||
import uuid
|
||||
from pathlib import Path
|
||||
|
||||
from app.domains.materials.library_paths import resolve_asset_library_blend_path
|
||||
from app.tasks.celery_app import celery_app
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -43,7 +44,20 @@ def refresh_asset_library_catalog(self, asset_library_id: str) -> None:
|
||||
if not lib:
|
||||
logger.warning("AssetLibrary %s not found", asset_library_id)
|
||||
return
|
||||
blend_path = lib.blend_file_path
|
||||
resolved_path = resolve_asset_library_blend_path(
|
||||
blend_file_path=lib.blend_file_path,
|
||||
asset_library_id=lib.id,
|
||||
)
|
||||
if resolved_path and resolved_path != lib.blend_file_path:
|
||||
logger.warning(
|
||||
"AssetLibrary %s path repaired from %s to %s before catalog refresh",
|
||||
asset_library_id,
|
||||
lib.blend_file_path,
|
||||
resolved_path,
|
||||
)
|
||||
lib.blend_file_path = resolved_path
|
||||
db.commit()
|
||||
blend_path = resolved_path or lib.blend_file_path
|
||||
engine.dispose()
|
||||
|
||||
if not blend_path or not Path(blend_path).exists():
|
||||
|
||||
Reference in New Issue
Block a user