update test arena
This commit is contained in:
@@ -2,6 +2,10 @@ from flask import Flask
|
||||
from flask_sqlalchemy import SQLAlchemy
|
||||
from flask_login import LoginManager
|
||||
import os
|
||||
import threading
|
||||
import time
|
||||
import requests
|
||||
import json
|
||||
|
||||
db = SQLAlchemy()
|
||||
login_manager = LoginManager()
|
||||
@@ -73,5 +77,23 @@ def create_app():
|
||||
except Exception as e:
|
||||
# Admin user might already exist, rollback and continue
|
||||
db.session.rollback()
|
||||
|
||||
|
||||
# Start background polling thread
|
||||
def poll_jobs():
|
||||
with app.app_context():
|
||||
from app.models import Job
|
||||
from app.routes.jobs import update_job_status_internal
|
||||
while True:
|
||||
try:
|
||||
# Poll all jobs that are not finished
|
||||
unfinished_jobs = Job.query.filter(Job.status.in_(['waiting', 'in_progress'])).all()
|
||||
for job in unfinished_jobs:
|
||||
update_job_status_internal(job)
|
||||
except Exception as e:
|
||||
print(f"[ERROR] Background polling error: {e}")
|
||||
time.sleep(20)
|
||||
|
||||
polling_thread = threading.Thread(target=poll_jobs, daemon=True)
|
||||
polling_thread.start()
|
||||
|
||||
return app
|
||||
|
||||
Reference in New Issue
Block a user