tfrere commited on
Commit
5b8ed2c
·
1 Parent(s): 7e0c218

add healthcheck to server

Browse files
Files changed (2) hide show
  1. main.py +6 -1
  2. src/server.py +6 -1
main.py CHANGED
@@ -14,6 +14,7 @@ import logging
14
  from dotenv import load_dotenv
15
  import uvicorn
16
  import sys
 
17
 
18
  # Import from src modules
19
  from src.processor import process_leaderboards
@@ -79,8 +80,12 @@ def run_server_mode(args):
79
  # Log startup information
80
  logger.info("Running in server mode with periodic processing")
81
 
 
 
 
 
82
  # Run the FastAPI server
83
- uvicorn.run(app, host="0.0.0.0", port=5176)
84
  except KeyboardInterrupt:
85
  logger.info("Server stopped by user")
86
  except Exception as e:
 
14
  from dotenv import load_dotenv
15
  import uvicorn
16
  import sys
17
+ import os
18
 
19
  # Import from src modules
20
  from src.processor import process_leaderboards
 
80
  # Log startup information
81
  logger.info("Running in server mode with periodic processing")
82
 
83
+ # Get port from environment variable or use default HF Spaces port
84
+ port = int(os.environ.get("PORT", 7860))
85
+ logger.info(f"Starting server on port {port}")
86
+
87
  # Run the FastAPI server
88
+ uvicorn.run(app, host="0.0.0.0", port=port)
89
  except KeyboardInterrupt:
90
  logger.info("Server stopped by user")
91
  except Exception as e:
src/server.py CHANGED
@@ -190,4 +190,9 @@ async def trigger_run():
190
  # Start processing in a separate thread
191
  threading.Thread(target=lambda: process_leaderboards()).start()
192
 
193
- return {"status": "started", "message": "Processing started"}
 
 
 
 
 
 
190
  # Start processing in a separate thread
191
  threading.Thread(target=lambda: process_leaderboards()).start()
192
 
193
+ return {"status": "started", "message": "Processing started"}
194
+
195
+ @app.get("/health")
196
+ async def health_check():
197
+ """Health check endpoint for HF Spaces to verify the app is running"""
198
+ return {"status": "ok"}