Elliotasdasdasfasas commited on
Commit
b33d06f
·
1 Parent(s): e318c1f

Fix Brain3: Lazy Tunnel Start to prevent 503

Browse files
Files changed (1) hide show
  1. app.py +19 -5
app.py CHANGED
@@ -7,14 +7,28 @@ app = FastAPI()
7
  bridge = None
8
 
9
  @app.on_event("startup")
10
- def startup_event():
11
  global bridge
12
- print("🚀 Starting Brain3...")
13
- bridge = AzureSFTPBridge()
 
 
 
 
 
 
 
 
 
 
 
 
14
  if os.environ.get("SSH_KEY"):
15
- bridge.start_tunnel()
 
 
16
  else:
17
- print("⚠️ SSH_KEY missing. Bridge disabled.")
18
 
19
  @app.get("/")
20
  def home():
 
7
  bridge = None
8
 
9
  @app.on_event("startup")
10
+ async def startup_event():
11
  global bridge
12
+ print("🚀 Brain3 Starting (Lazy Bridge Mode)...")
13
+ # Initialize object but DO NOT start tunnel yet
14
+ try:
15
+ bridge = AzureSFTPBridge()
16
+ print("✅ Bridge initialized (Tunnel Pending)")
17
+ except Exception as e:
18
+ print(f"⚠️ Bridge init failed: {e}")
19
+
20
+ @app.get("/start-bridge")
21
+ def trigger_bridge():
22
+ """Manually start the tunnel."""
23
+ global bridge
24
+ if not bridge: return {"error": "Bridge not init"}
25
+
26
  if os.environ.get("SSH_KEY"):
27
+ # Start in thread to not block response
28
+ threading.Thread(target=bridge.start_tunnel, daemon=True).start()
29
+ return {"status": "Tunnel starting in background..."}
30
  else:
31
+ return {"error": "SSH_KEY missing"}
32
 
33
  @app.get("/")
34
  def home():