-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun.py
More file actions
68 lines (54 loc) · 1.99 KB
/
Copy pathrun.py
File metadata and controls
68 lines (54 loc) · 1.99 KB
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import os
import subprocess
import sys
import time
import urllib.request
import json
def spawn_process(command, cwd):
if os.name == "nt" and command[0] == "npm":
command = ["npm.cmd", *command[1:]]
return subprocess.Popen(command, cwd=cwd)
def wait_for_backend(url="http://127.0.0.1:8008/health", timeout=30):
print("Waiting for backend...", end="", flush=True)
start = time.time()
while time.time() - start < timeout:
try:
# Using urllib instead of requests to avoid external dependencies in startup script
proxy_handler = urllib.request.ProxyHandler({})
opener = urllib.request.build_opener(proxy_handler)
with opener.open(url, timeout=2) as response:
if response.status == 200:
data = json.loads(response.read().decode())
if data.get("status") == "ok":
print(" ready.")
return True
except Exception:
pass
print(".", end="", flush=True)
time.sleep(1)
print(" FAILED. Check backend logs.")
return False
def run():
root = os.path.dirname(os.path.abspath(__file__))
print("FININTEL PLATFORM STARTUP")
print("------------------------------------------")
print("Starting backend API...")
backend = spawn_process([sys.executable, "-m", "backend.main"], cwd=root)
if not wait_for_backend():
print("Backend failed to start. Terminating startup.")
backend.terminate()
sys.exit(1)
print("Starting frontend dashboard...")
frontend = spawn_process(["npm", "run", "dev", "--", "--host", "0.0.0.0"], cwd=root)
print("\nDashboard is live at http://localhost:5173")
print("Press Ctrl+C to shut down.")
try:
while True:
time.sleep(1)
except KeyboardInterrupt:
print("\nShutting down services...")
backend.terminate()
frontend.terminate()
sys.exit(0)
if __name__ == "__main__":
run()