From 1a308153fa8614ceb3ff3e07386322e5142974ce Mon Sep 17 00:00:00 2001 From: ascibisz Date: Wed, 4 Nov 2026 14:09:24 -0800 Subject: [PATCH 1/2] prefetch grid files for cellpack client --- docker/server.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/docker/server.py b/docker/server.py index 9bcac051..3b83c470 100644 --- a/docker/server.py +++ b/docker/server.py @@ -1,5 +1,6 @@ import asyncio from aiohttp import web +from cellpack.autopack import get_local_file_location from cellpack.autopack.DBRecipeHandler import DataDoc, DBUploader from cellpack.autopack.interface_objects.database_ids import DATABASE_IDS from cellpack.bin.pack import pack @@ -25,6 +26,34 @@ def job_exists(self, dedup_hash): job_status, _ = db.get_doc_by_id("job_status", dedup_hash) return job_status is not None + def prefetch_example_grid_files(self): + """ + Download grid files for all example cellpack client recipes into the local + cache so they are ready before the server starts accepting packing requests + """ + db = self._get_firebase_handler() + if not db: + return + + recipe_docs = db.get_all_docs("example_packings") + if not recipe_docs: + return + + for doc in recipe_docs: + recipe_data = doc.to_dict() + recipe_id = recipe_data.get("recipe") + if not recipe_id: + continue + + recipe_doc, _ = db.get_doc_by_id("recipes", recipe_id) + if not recipe_doc: + continue + + grid_file_path = recipe_doc.get("grid_file_path") + if grid_file_path: + # Downloads grid file to the local cache if its not already present + get_local_file_location(grid_file_path, cache="grids") + async def run_packing(self, dedup_hash, recipe, config=None): self.update_job_status(dedup_hash, "RUNNING") try: @@ -84,6 +113,7 @@ async def pack_handler(self, request: web.Request) -> web.Response: async def init_app() -> web.Application: app = web.Application() server = CellpackServer() + server.prefetch_example_grid_files() app.add_routes( [ web.get("/hello", server.hello_world), From d2dc818684ffe7490e86f2123c7f59729a2e624c Mon Sep 17 00:00:00 2001 From: ascibisz Date: Wed, 4 Nov 2026 14:25:48 -0800 Subject: [PATCH 2/2] add try block so we don't fail to start app on exception --- docker/server.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/docker/server.py b/docker/server.py index 3b83c470..5aff6f59 100644 --- a/docker/server.py +++ b/docker/server.py @@ -51,8 +51,12 @@ def prefetch_example_grid_files(self): grid_file_path = recipe_doc.get("grid_file_path") if grid_file_path: - # Downloads grid file to the local cache if its not already present - get_local_file_location(grid_file_path, cache="grids") + try: + # Downloads grid file to the local cache if its not already present + get_local_file_location(grid_file_path, cache="grids") + except Exception as e: + # Don't let a failed prefetch prevent the server from starting + print(f"Failed to prefetch grid file '{grid_file_path}': {e}") async def run_packing(self, dedup_hash, recipe, config=None): self.update_job_status(dedup_hash, "RUNNING")