File size: 786 Bytes
4d7f3f1
 
11a060b
e88e203
eb6f602
40ddc07
 
4d7f3f1
 
 
fc7608c
 
4d7f3f1
 
 
ee67785
40ddc07
4d7f3f1
 
 
 
 
 
 
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
from fastapi import FastAPI
import subprocess

app = FastAPI()

@app.get("/start")
def start_task():
    try:
        # Run each script one by one
        subprocess.run(["python", "model_split.py"], check=True)
        subprocess.run(["python", "ray_node.py"], check=True)
        subprocess.run(["python", "head_node.py"], check=True)
        return {"message": "All scripts executed successfully"}
    except subprocess.CalledProcessError as e:
        return {"error": f"Script failed: {e}"}

@app.get("/stop")
def stop_ray():
    try:
        # This stops all Ray processes
        subprocess.run(["ray", "stop"], check=True)
        return {"message": "Ray stopped successfully"}
    except subprocess.CalledProcessError as e:
        return {"error": f"Failed to stop Ray: {e}"}