DeepLearning101 commited on
Commit
8b76969
·
verified ·
1 Parent(s): 62d26a7

唯讀查詢

Browse files
Files changed (1) hide show
  1. main.py +16 -0
main.py CHANGED
@@ -138,6 +138,22 @@ def read_root():
138
  return {"status": "online", "message": "Cié Cié FastAPI is running."}
139
 
140
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
141
  @app.post("/api/submit_booking")
142
  async def submit_booking(payload: OrderPayload):
143
  if not supabase:
 
138
  return {"status": "online", "message": "Cié Cié FastAPI is running."}
139
 
140
 
141
+ @app.get("/api/health")
142
+ def health_check():
143
+ """輕量健康檢查:打一次 Supabase(唯讀),同時確認 DB 連線存活。
144
+
145
+ 供 keep-alive 排程使用:HF Space 48 小時、Supabase 7 天無活動會休眠,
146
+ 定期打這個端點可同時保住兩邊。唯讀查詢,不產生任何資料異動。
147
+ """
148
+ if not supabase:
149
+ raise HTTPException(status_code=503, detail="資料庫未設定")
150
+ try:
151
+ supabase.table("bookings").select("id").limit(1).execute()
152
+ except Exception as e:
153
+ raise HTTPException(status_code=503, detail=f"資料庫連線失敗: {e}")
154
+ return {"status": "ok", "db": "reachable"}
155
+
156
+
157
  @app.post("/api/submit_booking")
158
  async def submit_booking(payload: OrderPayload):
159
  if not supabase: