File size: 1,529 Bytes
b25b8f2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import subprocess
import time
import sys
import os
import signal

services = [
    ("services/input_receiver", 8000),
    ("services/preprocessing_service", 8001),
    ("services/ocr_service", 8002),
    ("services/representation_service", 8003),
    ("services/verification_service", 8004),
    ("services/classifier_service", 8005),
    ("services/reporting_service", 8006),
]

processes = []

def start_services():
    print("Starting all microservices locally...")
    for path, port in services:
        print(f"Starting {os.path.basename(path)} on port {port}...")
        env = os.environ.copy()
        
        # Use python -m uvicorn app:app --port 
        # (Assuming app.py is the main file name due to the recent cleanup script!)
        p = subprocess.Popen(
            [sys.executable, "-m", "uvicorn", "app:app", "--host", "127.0.0.0", "--port", str(port)],
            cwd=path,
            env=env,
            stdout=subprocess.DEVNULL,
            stderr=subprocess.DEVNULL
        )
        processes.append(p)

    print("Giving services 5 seconds to boot up...")
    time.sleep(5)

def stop_services():
    print("Stopping all microservices...")
    for p in processes:
        p.terminate()
        p.wait()
    print("All services stopped.")

if __name__ == "__main__":
    try:
        start_services()
        print("Running Benchmark...")
        subprocess.run([sys.executable, "scripts/benchmark_gsm8k.py"])
    finally:
        stop_services()