Fix real-time job status updates

- Add updated_at column to processing_queue table for tracking status changes
- Update update_queue_status to set updated_at timestamp on changes
- Modify job_status_updates API to use updated_at instead of created_at
- Add random parameter to API requests to prevent browser caching
parent 6ae5b0bc
......@@ -249,6 +249,7 @@ def init_db(conn) -> None:
result TEXT,
error_message TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
started_at TIMESTAMP NULL,
completed_at TIMESTAMP NULL,
estimated_time INT,
......@@ -271,6 +272,7 @@ def init_db(conn) -> None:
result TEXT,
error_message TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
started_at TIMESTAMP,
completed_at TIMESTAMP,
estimated_time INTEGER,
......@@ -640,6 +642,16 @@ def init_db(conn) -> None:
# Column might already exist
pass
# Add updated_at column to processing_queue table if it doesn't exist
try:
if config['type'] == 'mysql':
cursor.execute('ALTER TABLE processing_queue ADD COLUMN updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP')
else:
cursor.execute('ALTER TABLE processing_queue ADD COLUMN updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP')
except:
# Column might already exist
pass
# Cluster processes table
if config['type'] == 'mysql':
cursor.execute('''
......@@ -1173,7 +1185,7 @@ def update_queue_status(queue_id: int, status: str, result: dict = None, error:
conn = get_db_connection()
cursor = conn.cursor()
update_fields = ['status = ?']
update_fields = ['status = ?', 'updated_at = CURRENT_TIMESTAMP']
params = [status]
if status == 'processing':
......
......@@ -521,8 +521,8 @@ def api_job_status_updates():
updates = []
for job in queue_items:
# Convert job timestamps to comparable format
job_time = job.get('created_at')
# Convert job timestamps to comparable format (use updated_at if available, otherwise created_at)
job_time = job.get('updated_at') or job.get('created_at')
if isinstance(job_time, str):
# Parse timestamp string
from datetime import datetime
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment