baseball-engine / tools /start_api.py
github-actions[bot]
Automated Deploy: acb55f69ee3929c586c3ebc183e5ee1e69ca2acb
9756876
Raw History Blame Contribute Delete
1.12 kB
"""Prepare SAM once at startup, then run the existing API even if setup is unavailable."""
import os
from pathlib import Path
import subprocess
import sys
import json
def main():
worker=Path('/opt/sam-runtime/bin/python')
if worker.is_file() and os.environ.get('BASEBALL_SAM_SKIP_SETUP')!='1':
try:
subprocess.run([str(worker),'-m','tools.prepare_sam_assets'],timeout=600,check=False)
except subprocess.TimeoutExpired:
path=Path(os.environ.get('BASEBALL_DATA_ROOT','/data'))/'sam-setup-status.json'
path.write_text(json.dumps({'status':'unavailable','reason_code':'sam_asset_setup_timeout'}))
from tools.setup_gvhmr_api_worker import launch_optional_setup
try:launch_optional_setup()
except OSError:
print('GVHMR optional setup could not start; continuing API startup',flush=True)
os.execv(sys.executable,[sys.executable,'-m','uvicorn','baseball_batting.api:create_app','--factory',
'--host','0.0.0.0','--port','8000','--workers','1','--timeout-graceful-shutdown','20','--no-access-log'])
if __name__=='__main__':main()