53 lines
1.5 KiB
Python
53 lines
1.5 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Launch a second IfixKart backend instance pointed at the simulation schemas.
|
|
|
|
The normal backend keeps running on :8000 against production data. This process
|
|
loads Backend/.env.sim (generated by provision_sim_db.py) and listens on :8001.
|
|
|
|
Usage:
|
|
cd Backend
|
|
./venv/bin/python scripts/sim/run_sim_backend.py
|
|
./venv/bin/python scripts/sim/run_sim_backend.py --port 8001 --reload
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
import os
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
BACKEND_DIR = Path(__file__).resolve().parents[2]
|
|
if str(BACKEND_DIR) not in sys.path:
|
|
sys.path.insert(0, str(BACKEND_DIR))
|
|
SIM_ENV = BACKEND_DIR / ".env.sim"
|
|
|
|
|
|
def main() -> int:
|
|
parser = argparse.ArgumentParser()
|
|
parser.add_argument("--host", default="127.0.0.1")
|
|
parser.add_argument("--port", type=int, default=8001)
|
|
parser.add_argument("--reload", action="store_true")
|
|
args = parser.parse_args()
|
|
|
|
if not SIM_ENV.exists():
|
|
raise SystemExit(f"Missing {SIM_ENV}; run provision_sim_db.py first")
|
|
os.chdir(BACKEND_DIR)
|
|
# Load before importing the app so pydantic Settings sees these values.
|
|
from dotenv import load_dotenv
|
|
load_dotenv(SIM_ENV, override=True)
|
|
os.environ.setdefault("ENVIRONMENT", "simulation")
|
|
|
|
import uvicorn
|
|
uvicorn.run(
|
|
"app.main:app",
|
|
host=args.host,
|
|
port=args.port,
|
|
reload=args.reload,
|
|
log_level="info",
|
|
)
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|