Skip to content

Commit

Permalink
Improve app loader
Browse files Browse the repository at this point in the history
  • Loading branch information
oeway committed Mar 2, 2024
1 parent 072c21a commit db927cb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
25 changes: 22 additions & 3 deletions bioengine/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import asyncio
from bioengine.app_loader import load_apps
import logging

Expand All @@ -6,8 +7,26 @@
def connect_server(server_url):
raise NotImplementedError("This function is not implemented yet.")

async def register_bioengine_apps(server):
async def run_app_with_error_logging(app, server, continue_on_error):
try:
return await app.run(server)
except Exception as e:
logger.error(f"Error running service {app.name}: {str(e)}")
if not continue_on_error:
raise
else:
return e

async def register_bioengine_apps(server, continue_on_error=False):
futures = []
app_names = []
for app in load_apps():
app_names.append(app.name)
logger.info(f"Registering service {app.name}")
await app.run(server)
logger.info(f"Service {app.name} registered.")
futures.append(run_app_with_error_logging(app, server, continue_on_error))

results = await asyncio.gather(*futures)
summary = {name: ("✔️" if result is not None else "❌") for name, result in zip(app_names, results)}

for app_name, status in summary.items():
print(f"{app_name}: {status}")
4 changes: 3 additions & 1 deletion bioengine/app_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@ def load_apps():
current_dir = Path(__file__).parent
apps_dir = current_dir.parent / "apps"
# list folders under apps_dir
apps = []
for app_dir in apps_dir.iterdir():
if app_dir.is_dir():
manifest_file = app_dir / "manifest.yaml"
if manifest_file.exists():
manifest = safe_load(manifest_file.read_text())
yield AppInfo.parse_obj(manifest)
apps.append(AppInfo.parse_obj(manifest))
return apps

0 comments on commit db927cb

Please sign in to comment.