File size: 1,116 Bytes
b13d358
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9756876
 
 
 
b13d358
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
"""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()