Spaces:
Sleeping
Sleeping
update55
Browse files
app.py
CHANGED
@@ -374,13 +374,25 @@ def check_status(task_id):
|
|
374 |
def get_queue_status():
|
375 |
"""Get queue status"""
|
376 |
with lock:
|
|
|
377 |
queued_tasks = [t for t in task_status.values() if t['status'] == 'queued']
|
378 |
processing_tasks = [t for t in task_status.values() if t['status'] == 'processing']
|
379 |
|
380 |
-
|
|
|
|
|
|
|
|
|
381 |
active_tasks = len(processing_tasks)
|
382 |
waiting_tasks = queue_size
|
383 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
384 |
remaining_processing_time = 0
|
385 |
for task in processing_tasks:
|
386 |
if 'start_time' in task and 'estimated_time' in task:
|
|
|
374 |
def get_queue_status():
|
375 |
"""Get queue status"""
|
376 |
with lock:
|
377 |
+
# Get all tasks that are either queued or processing
|
378 |
queued_tasks = [t for t in task_status.values() if t['status'] == 'queued']
|
379 |
processing_tasks = [t for t in task_status.values() if t['status'] == 'processing']
|
380 |
|
381 |
+
# Get the actual queue size from the queue object
|
382 |
+
actual_queue_size = task_queue.qsize()
|
383 |
+
|
384 |
+
# Use the larger of actual queue size or queued tasks count
|
385 |
+
queue_size = max(actual_queue_size, len(queued_tasks))
|
386 |
active_tasks = len(processing_tasks)
|
387 |
waiting_tasks = queue_size
|
388 |
|
389 |
+
# Clean up completed or error tasks that are older than 1 hour
|
390 |
+
current_time = time.time()
|
391 |
+
for task_id in list(task_status.keys()):
|
392 |
+
if task_status[task_id]['status'] in ['completed', 'error']:
|
393 |
+
if current_time - task_status[task_id].get('end_time', 0) > 3600:
|
394 |
+
task_status.pop(task_id, None)
|
395 |
+
|
396 |
remaining_processing_time = 0
|
397 |
for task in processing_tasks:
|
398 |
if 'start_time' in task and 'estimated_time' in task:
|