-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi_watcher.py
More file actions
55 lines (47 loc) · 1.35 KB
/
api_watcher.py
File metadata and controls
55 lines (47 loc) · 1.35 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
import os
import signal
import subprocess
import sys
from pathlib import Path
from watchfiles import watch
ROOT = Path('/app')
CONFIG = ROOT / 'langgraph.json'
AGENTS = ROOT / 'agents'
CMD = [
'langgraph', 'dev',
'--host', '0.0.0.0',
'--port', '8000',
'--config', 'langgraph.json',
'--no-reload',
'--no-browser',
]
def run_server():
print('[watcher] starting langgraph:', ' '.join(CMD), flush=True)
return subprocess.Popen(CMD)
def main():
proc = run_server()
try:
for changes in watch(CONFIG, AGENTS, stop_event=None):
print(f'[watcher] detected changes: {changes}', flush=True)
# Restart the server
if proc.poll() is None:
try:
proc.terminate()
try:
proc.wait(timeout=10)
except subprocess.TimeoutExpired:
proc.kill()
except Exception as e:
print(f'[watcher] error terminating: {e}', flush=True)
proc = run_server()
except KeyboardInterrupt:
pass
finally:
if proc and proc.poll() is None:
proc.terminate()
try:
proc.wait(timeout=5)
except subprocess.TimeoutExpired:
proc.kill()
if __name__ == '__main__':
sys.exit(main())