Spaces:
Build error
Build error
update on server ui
Browse files- src/scheduler.py +7 -2
- src/server.py +64 -3
src/scheduler.py
CHANGED
|
@@ -71,8 +71,13 @@ def scheduler_thread():
|
|
| 71 |
args_to_use["ignore_cooldown"] = True
|
| 72 |
logger.info("Using --ignore-cooldown option in scheduled processing")
|
| 73 |
|
| 74 |
-
|
| 75 |
-
logger.info(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
|
| 77 |
# Wait at least 80% of the interval before checking again
|
| 78 |
# This prevents multiple executions and provides a buffer
|
|
|
|
| 71 |
args_to_use["ignore_cooldown"] = True
|
| 72 |
logger.info("Using --ignore-cooldown option in scheduled processing")
|
| 73 |
|
| 74 |
+
# Run in a separate thread to avoid blocking the main thread
|
| 75 |
+
logger.info("Starting processing job in a separate thread")
|
| 76 |
+
processing_thread = threading.Thread(
|
| 77 |
+
target=lambda: process_leaderboards_function(args_to_use)
|
| 78 |
+
)
|
| 79 |
+
processing_thread.daemon = True
|
| 80 |
+
processing_thread.start()
|
| 81 |
|
| 82 |
# Wait at least 80% of the interval before checking again
|
| 83 |
# This prevents multiple executions and provides a buffer
|
src/server.py
CHANGED
|
@@ -48,6 +48,12 @@ async def root():
|
|
| 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>
|
|
@@ -65,7 +71,7 @@ async def root():
|
|
| 65 |
}}
|
| 66 |
.status-box {{
|
| 67 |
padding: 30px;
|
| 68 |
-
text-align:
|
| 69 |
background-color: white;
|
| 70 |
border-radius: 12px;
|
| 71 |
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.05);
|
|
@@ -89,15 +95,70 @@ async def root():
|
|
| 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>
|
| 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
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
</body>
|
| 102 |
</html>
|
| 103 |
"""
|
|
|
|
| 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 |
+
# Calculate timestamp for next run to use in JavaScript
|
| 52 |
+
next_run_timestamp = ""
|
| 53 |
+
if last_run_time:
|
| 54 |
+
next_run_time = last_run_time + datetime.timedelta(hours=int(os.environ.get("LEADERBOARD_REPROCESS_INTERVAL_HOURS", 24)))
|
| 55 |
+
next_run_timestamp = next_run_time.timestamp() * 1000 # Convert to milliseconds for JavaScript
|
| 56 |
+
|
| 57 |
html_content = f"""
|
| 58 |
<!DOCTYPE html>
|
| 59 |
<html>
|
|
|
|
| 71 |
}}
|
| 72 |
.status-box {{
|
| 73 |
padding: 30px;
|
| 74 |
+
text-align: center;
|
| 75 |
background-color: white;
|
| 76 |
border-radius: 12px;
|
| 77 |
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.05);
|
|
|
|
| 95 |
.status-running {{ color: #1a73e8; font-weight: bold; }}
|
| 96 |
.status-idle {{ color: #188038; font-weight: bold; }}
|
| 97 |
.status-failed {{ color: #d93025; font-weight: bold; }}
|
| 98 |
+
.countdown {{
|
| 99 |
+
margin-top: 10px;
|
| 100 |
+
padding: 8px;
|
| 101 |
+
background-color: #f5f5f5;
|
| 102 |
+
border-radius: 6px;
|
| 103 |
+
display: inline-block;
|
| 104 |
+
min-width: 250px;
|
| 105 |
+
}}
|
| 106 |
</style>
|
| 107 |
</head>
|
| 108 |
<body>
|
| 109 |
<div class="status-box">
|
| 110 |
+
<h1>Leaderboard Parser</h1>
|
| 111 |
<p><span class="status-label">Status</span> <span class="status-{processing_status}">{processing_status}</span></p>
|
| 112 |
<p><span class="status-label">Last run</span> {last_run}</p>
|
| 113 |
+
{f'<p style="color: #d93025; margin-top: 20px;"><span class="status-label">Error</span> {processing_error}</p>' if processing_error else ''}
|
| 114 |
+
|
| 115 |
+
<div class="countdown" id="countdown">
|
| 116 |
+
Calculating time remaining...
|
| 117 |
+
</div>
|
| 118 |
</div>
|
| 119 |
+
|
| 120 |
+
<script>
|
| 121 |
+
// Set the date we're counting down to (from server)
|
| 122 |
+
const nextRunTimestamp = {next_run_timestamp};
|
| 123 |
+
|
| 124 |
+
// Function to format time remaining in a human-readable way
|
| 125 |
+
function formatTimeRemaining(distance) {{
|
| 126 |
+
const hours = Math.floor(distance / (1000 * 60 * 60));
|
| 127 |
+
const minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
|
| 128 |
+
const seconds = Math.floor((distance % (1000 * 60)) / 1000);
|
| 129 |
+
|
| 130 |
+
return `Next run in <b>${{hours}}h ${{minutes}}m ${{seconds}}s</b>`;
|
| 131 |
+
}}
|
| 132 |
+
|
| 133 |
+
// Update the countdown every 1 second
|
| 134 |
+
function updateCountdown() {{
|
| 135 |
+
// Get current timestamp
|
| 136 |
+
const now = new Date().getTime();
|
| 137 |
+
|
| 138 |
+
// If no next run is scheduled
|
| 139 |
+
if (!nextRunTimestamp) {{
|
| 140 |
+
document.getElementById("countdown").innerHTML = "No next run scheduled";
|
| 141 |
+
return;
|
| 142 |
+
}}
|
| 143 |
+
|
| 144 |
+
// Find the time remaining
|
| 145 |
+
const distance = nextRunTimestamp - now;
|
| 146 |
+
|
| 147 |
+
// If the countdown is over
|
| 148 |
+
if (distance < 0) {{
|
| 149 |
+
document.getElementById("countdown").innerHTML = "Scheduled run in progress or overdue";
|
| 150 |
+
}} else {{
|
| 151 |
+
// Display the result
|
| 152 |
+
document.getElementById("countdown").innerHTML = formatTimeRemaining(distance);
|
| 153 |
+
}}
|
| 154 |
+
}}
|
| 155 |
+
|
| 156 |
+
// Initial call to display right away
|
| 157 |
+
updateCountdown();
|
| 158 |
+
|
| 159 |
+
// Set up interval to update every second
|
| 160 |
+
setInterval(updateCountdown, 1000);
|
| 161 |
+
</script>
|
| 162 |
</body>
|
| 163 |
</html>
|
| 164 |
"""
|