Skip to content

Commit 220df48

Browse files
committed
Refactor asset handling in concurrency utilities, update asset type key, and improve thumbnail preview logic
1 parent b26e58f commit 220df48

File tree

4 files changed

+14
-250
lines changed

4 files changed

+14
-250
lines changed

.vscode/launch.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@
174174
"MAX_ASSET_COUNT": "3",
175175
"SKIP_UPDATE": "True",
176176
// optional, for testing a specific asset "ASSET_BASE_ID"
177+
"ASSET_BASE_ID": "a200d4c6-ac79-4554-9730-8103cc137749"
177178
}
178179

179180
},

blender_bg_scripts/autothumb_wireframe_bg.py

Lines changed: 0 additions & 244 deletions
This file was deleted.

blenderkit_server_utils/concurrency.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def _thread_target(
8484
logger.debug("Starting thread for asset %s", asset)
8585
asset_keys_snapshot = (
8686
asset.get("id", ""),
87-
asset.get("type", ""),
87+
asset.get("assetType", ""),
8888
asset.get("name", "N/A"),
8989
)
9090
t = threading.Thread(

render_thumbnail.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -291,10 +291,8 @@ def _run_bg_render(
291291
raise RuntimeError(f"BG render failed (script={script_name}, ret={ret})")
292292

293293

294-
def _maybe_preview_and_return(result_filepath: str) -> bool:
295-
"""Preview result and return True when SKIP_UPDATE is enabled."""
296-
if not SKIP_UPDATE:
297-
return False
294+
def _preview_and_return(result_filepath: str) -> bool:
295+
"""Preview result and return True is enabled."""
298296
try:
299297
from PIL import Image # lazy import
300298

@@ -304,6 +302,7 @@ def _maybe_preview_and_return(result_filepath: str) -> bool:
304302
opened = utils.open_folder(result_filepath)
305303
if not opened:
306304
logger.error("Failed to open folder %s", os.path.dirname(result_filepath))
305+
return False
307306
return True
308307

309308

@@ -361,8 +360,16 @@ def render_thumbnail_thread(asset_data: dict[str, Any], api_key: str) -> None:
361360

362361
# Render and upload
363362
_run_bg_render(asset_data, asset_file_path, template_path, result_filepath, script_name)
364-
if _maybe_preview_and_return(result_filepath):
363+
364+
if SKIP_UPDATE:
365+
was_opened = _preview_and_return(result_filepath)
366+
if not was_opened:
367+
# clear temp folder if we failed to open it
368+
if asset_file_path and os.path.isfile(asset_file_path):
369+
os.remove(asset_file_path)
370+
utils.cleanup_temp(temp_folder)
365371
return
372+
366373
_upload_and_clear(asset_data, api_key, result_filepath)
367374

368375
except Exception:

0 commit comments

Comments
 (0)