Spaces:
Build error
Build error
add minimal ui for agent state
Browse files- main.py +1 -1
- src/processor.py +7 -1
- src/server.py +67 -10
main.py
CHANGED
@@ -80,7 +80,7 @@ def run_server_mode(args):
|
|
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=
|
84 |
except KeyboardInterrupt:
|
85 |
logger.info("Server stopped by user")
|
86 |
except Exception as e:
|
|
|
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:
|
src/processor.py
CHANGED
@@ -32,7 +32,7 @@ def update_server_status(status, error=None):
|
|
32 |
error: The error message in case of failure
|
33 |
"""
|
34 |
try:
|
35 |
-
from src.server import processing_status, processing_error
|
36 |
|
37 |
# Update global variables in server.py
|
38 |
globals()['processing_status'] = status
|
@@ -42,6 +42,12 @@ def update_server_status(status, error=None):
|
|
42 |
import src.server
|
43 |
src.server.processing_status = status
|
44 |
src.server.processing_error = error
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
except ImportError:
|
46 |
# In non-server mode, these variables don't exist
|
47 |
pass
|
|
|
32 |
error: The error message in case of failure
|
33 |
"""
|
34 |
try:
|
35 |
+
from src.server import processing_status, processing_error, last_run_time
|
36 |
|
37 |
# Update global variables in server.py
|
38 |
globals()['processing_status'] = status
|
|
|
42 |
import src.server
|
43 |
src.server.processing_status = status
|
44 |
src.server.processing_error = error
|
45 |
+
|
46 |
+
# Update last run time when processing completes
|
47 |
+
if status == "completed":
|
48 |
+
now = datetime.datetime.now()
|
49 |
+
src.server.last_run_time = now
|
50 |
+
logger.info(f"Updated last run time to {now.isoformat()}")
|
51 |
except ImportError:
|
52 |
# In non-server mode, these variables don't exist
|
53 |
pass
|
src/server.py
CHANGED
@@ -7,7 +7,7 @@ import threading
|
|
7 |
import logging
|
8 |
import os
|
9 |
from fastapi import FastAPI, HTTPException
|
10 |
-
from fastapi.responses import JSONResponse
|
11 |
from src.file_utils import format_datetime
|
12 |
|
13 |
# Initialiser le logger
|
@@ -32,19 +32,76 @@ def initialize_server(process_function):
|
|
32 |
Args:
|
33 |
process_function: Fonction qui traite les leaderboards
|
34 |
"""
|
35 |
-
global process_leaderboards
|
36 |
process_leaderboards = process_function
|
37 |
-
|
|
|
|
|
|
|
38 |
|
39 |
# Endpoints API
|
40 |
-
@app.get("/")
|
41 |
async def root():
|
42 |
-
"""Root endpoint
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
|
49 |
@app.get("/status")
|
50 |
async def get_status():
|
|
|
7 |
import logging
|
8 |
import os
|
9 |
from fastapi import FastAPI, HTTPException
|
10 |
+
from fastapi.responses import JSONResponse, HTMLResponse
|
11 |
from src.file_utils import format_datetime
|
12 |
|
13 |
# Initialiser le logger
|
|
|
32 |
Args:
|
33 |
process_function: Fonction qui traite les leaderboards
|
34 |
"""
|
35 |
+
global process_leaderboards, last_run_time
|
36 |
process_leaderboards = process_function
|
37 |
+
|
38 |
+
# Initialiser last_run_time à la date actuelle
|
39 |
+
last_run_time = datetime.datetime.now()
|
40 |
+
logger.info(f"Serveur initialisé avec la fonction de traitement. last_run_time initialisé à {last_run_time.isoformat()}")
|
41 |
|
42 |
# Endpoints API
|
43 |
+
@app.get("/", response_class=HTMLResponse)
|
44 |
async def root():
|
45 |
+
"""Root endpoint serving a simple HTML page with status info"""
|
46 |
+
global processing_status, last_run_time, processing_error
|
47 |
+
|
48 |
+
next_run = format_datetime(last_run_time + datetime.timedelta(hours=int(os.environ.get("LEADERBOARD_REPROCESS_INTERVAL_HOURS", 24)))) if last_run_time else "Not yet scheduled"
|
49 |
+
last_run = format_datetime(last_run_time) if last_run_time else "Never"
|
50 |
+
|
51 |
+
html_content = f"""
|
52 |
+
<!DOCTYPE html>
|
53 |
+
<html>
|
54 |
+
<head>
|
55 |
+
<title>Leaderboard Parser Status</title>
|
56 |
+
<style>
|
57 |
+
body {{
|
58 |
+
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
59 |
+
display: flex;
|
60 |
+
justify-content: center;
|
61 |
+
align-items: center;
|
62 |
+
height: 100vh;
|
63 |
+
margin: 0;
|
64 |
+
background-color: #f7f7f7;
|
65 |
+
}}
|
66 |
+
.status-box {{
|
67 |
+
padding: 30px;
|
68 |
+
text-align: left;
|
69 |
+
background-color: white;
|
70 |
+
border-radius: 12px;
|
71 |
+
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.05);
|
72 |
+
max-width: 500px;
|
73 |
+
}}
|
74 |
+
h1 {{
|
75 |
+
margin-top: 0;
|
76 |
+
color: #333;
|
77 |
+
font-weight: 600;
|
78 |
+
}}
|
79 |
+
p {{
|
80 |
+
margin: 12px 0;
|
81 |
+
font-size: 16px;
|
82 |
+
line-height: 1.5;
|
83 |
+
}}
|
84 |
+
.status-label {{
|
85 |
+
font-weight: bold;
|
86 |
+
display: inline-block;
|
87 |
+
min-width: 80px;
|
88 |
+
}}
|
89 |
+
.status-running {{ color: #1a73e8; font-weight: bold; }}
|
90 |
+
.status-idle {{ color: #188038; font-weight: bold; }}
|
91 |
+
.status-failed {{ color: #d93025; font-weight: bold; }}
|
92 |
+
</style>
|
93 |
+
</head>
|
94 |
+
<body>
|
95 |
+
<div class="status-box">
|
96 |
+
<h1>Leaderboards parser agent</h1>
|
97 |
+
<p><span class="status-label">Status</span> <span class="status-{processing_status}">{processing_status}</span></p>
|
98 |
+
<p><span class="status-label">Last run</span> {last_run}</p>
|
99 |
+
{f'<p style="color: #d93025; margin-top: 20px;"><span class="status-label">Error:</span> {processing_error}</p>' if processing_error else ''}
|
100 |
+
</div>
|
101 |
+
</body>
|
102 |
+
</html>
|
103 |
+
"""
|
104 |
+
return HTMLResponse(content=html_content)
|
105 |
|
106 |
@app.get("/status")
|
107 |
async def get_status():
|