fix: use cache for input files instead of hardcoded paths
This commit is contained in:
31
tasks.py
31
tasks.py
@@ -54,12 +54,11 @@ def render_effect(self, input_hash: str, effect_name: str, output_name: str) ->
|
||||
Returns:
|
||||
Provenance record with output hash
|
||||
"""
|
||||
# Registry hashes
|
||||
# Cache directory (shared between server and worker)
|
||||
CACHE_DIR = Path(os.environ.get("CACHE_DIR", str(Path.home() / ".artdag" / "cache")))
|
||||
|
||||
# Registry hashes (for effects/infra metadata only)
|
||||
REGISTRY = {
|
||||
"cat": {
|
||||
"hash": "33268b6e167deaf018cc538de12dbe562612b33e89a749391cef855b320a269b",
|
||||
"path": Path.home() / "artdag-art" / "cat.jpg"
|
||||
},
|
||||
"effect:dog": {
|
||||
"hash": "d048fe313433eb4e38f0e24194ffae91b896ca3e6eed3e50b2cc37b7be495555"
|
||||
},
|
||||
@@ -74,27 +73,19 @@ def render_effect(self, input_hash: str, effect_name: str, output_name: str) ->
|
||||
}
|
||||
}
|
||||
|
||||
# Find input by hash
|
||||
input_asset = None
|
||||
input_name = None
|
||||
for name, data in REGISTRY.items():
|
||||
if data.get("hash") == input_hash and "path" in data:
|
||||
input_asset = data
|
||||
input_name = name
|
||||
break
|
||||
# Input comes from cache by hash
|
||||
input_path = CACHE_DIR / input_hash
|
||||
if not input_path.exists():
|
||||
raise ValueError(f"Input not in cache: {input_hash}")
|
||||
|
||||
if not input_asset:
|
||||
raise ValueError(f"Unknown input hash: {input_hash}")
|
||||
|
||||
input_path = input_asset["path"]
|
||||
output_dir = Path.home() / "artdag-art"
|
||||
output_dir = CACHE_DIR
|
||||
|
||||
# Verify input
|
||||
actual_hash = file_hash(input_path)
|
||||
if actual_hash != input_hash:
|
||||
raise ValueError(f"Input hash mismatch: expected {input_hash}, got {actual_hash}")
|
||||
|
||||
self.update_state(state='RENDERING', meta={'effect': effect_name, 'input': input_name})
|
||||
self.update_state(state='RENDERING', meta={'effect': effect_name, 'input': input_hash[:16]})
|
||||
|
||||
# Load and apply effect
|
||||
if effect_name == "dog":
|
||||
@@ -126,7 +117,7 @@ def render_effect(self, input_hash: str, effect_name: str, output_name: str) ->
|
||||
"local_path": str(result)
|
||||
},
|
||||
"inputs": [
|
||||
{"name": input_name, "content_hash": input_hash}
|
||||
{"content_hash": input_hash}
|
||||
],
|
||||
"effects": [
|
||||
{"name": f"effect:{effect_name}", "content_hash": REGISTRY[f"effect:{effect_name}"]["hash"]}
|
||||
|
||||
Reference in New Issue
Block a user