-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.py
More file actions
executable file
·108 lines (91 loc) · 2.81 KB
/
start.py
File metadata and controls
executable file
·108 lines (91 loc) · 2.81 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/usr/bin/env python3
"""
Start script for Pipeline Dashboard.
Runs FastAPI backend and Vite dev server.
"""
import subprocess
import sys
import os
import signal
import time
from pathlib import Path
ROOT = Path(__file__).parent
def check_dependencies():
"""Check if required dependencies are installed."""
try:
import fastapi
import uvicorn
except ImportError:
print("Installing Python dependencies...")
subprocess.run([sys.executable, "-m", "pip", "install", "-r", "requirements.txt"], cwd=ROOT)
dashboard = ROOT / "dashboard"
if not (dashboard / "node_modules").exists():
print("Installing frontend dependencies...")
subprocess.run(["npm", "install"], cwd=dashboard)
def main():
check_dependencies()
processes = []
shutting_down = False
def cleanup(sig=None, frame=None):
nonlocal shutting_down
if shutting_down:
return
shutting_down = True
print("\nShutting down...")
for p in processes:
try:
os.killpg(os.getpgid(p.pid), signal.SIGTERM)
except (ProcessLookupError, OSError):
pass
time.sleep(0.5)
for p in processes:
try:
os.killpg(os.getpgid(p.pid), signal.SIGKILL)
except (ProcessLookupError, OSError):
pass
sys.exit(0)
signal.signal(signal.SIGINT, cleanup)
signal.signal(signal.SIGTERM, cleanup)
env = os.environ.copy()
env["PYTHONPATH"] = str(ROOT)
print("Starting backend on http://localhost:4000")
backend = subprocess.Popen(
[sys.executable, "-m", "uvicorn", "src.api.main:app", "--host", "0.0.0.0", "--port", "4000", "--reload"],
cwd=ROOT,
env=env,
stdout=sys.stdout,
stderr=sys.stderr,
start_new_session=True
)
processes.append(backend)
time.sleep(2)
print("Starting frontend on http://localhost:4444")
frontend = subprocess.Popen(
["npm", "run", "dev"],
cwd=ROOT / "dashboard",
stdout=sys.stdout,
stderr=sys.stderr,
start_new_session=True
)
processes.append(frontend)
print("\n" + "=" * 50)
print("Pipeline Dashboard")
print("=" * 50)
print("Frontend: http://localhost:4444")
print("Backend: http://localhost:4000")
print("API Docs: http://localhost:4000/docs")
print("=" * 50)
print("Press Ctrl+C to stop\n")
try:
while True:
if backend.poll() is not None:
print("Backend stopped unexpectedly")
cleanup()
if frontend.poll() is not None:
print("Frontend stopped unexpectedly")
cleanup()
time.sleep(1)
except KeyboardInterrupt:
cleanup()
if __name__ == "__main__":
main()