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: ...@@ -249,6 +249,7 @@ def init_db(conn) -> None:
result TEXT, result TEXT,
error_message TEXT, error_message TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
started_at TIMESTAMP NULL, started_at TIMESTAMP NULL,
completed_at TIMESTAMP NULL, completed_at TIMESTAMP NULL,
estimated_time INT, estimated_time INT,
...@@ -271,6 +272,7 @@ def init_db(conn) -> None: ...@@ -271,6 +272,7 @@ def init_db(conn) -> None:
result TEXT, result TEXT,
error_message TEXT, error_message TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
started_at TIMESTAMP, started_at TIMESTAMP,
completed_at TIMESTAMP, completed_at TIMESTAMP,
estimated_time INTEGER, estimated_time INTEGER,
...@@ -640,6 +642,16 @@ def init_db(conn) -> None: ...@@ -640,6 +642,16 @@ def init_db(conn) -> None:
# Column might already exist # Column might already exist
pass 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 # Cluster processes table
if config['type'] == 'mysql': if config['type'] == 'mysql':
cursor.execute(''' cursor.execute('''
...@@ -1173,7 +1185,7 @@ def update_queue_status(queue_id: int, status: str, result: dict = None, error: ...@@ -1173,7 +1185,7 @@ def update_queue_status(queue_id: int, status: str, result: dict = None, error:
conn = get_db_connection() conn = get_db_connection()
cursor = conn.cursor() cursor = conn.cursor()
update_fields = ['status = ?'] update_fields = ['status = ?', 'updated_at = CURRENT_TIMESTAMP']
params = [status] params = [status]
if status == 'processing': if status == 'processing':
......
...@@ -521,8 +521,8 @@ def api_job_status_updates(): ...@@ -521,8 +521,8 @@ def api_job_status_updates():
updates = [] updates = []
for job in queue_items: for job in queue_items:
# Convert job timestamps to comparable format # Convert job timestamps to comparable format (use updated_at if available, otherwise created_at)
job_time = job.get('created_at') job_time = job.get('updated_at') or job.get('created_at')
if isinstance(job_time, str): if isinstance(job_time, str):
# Parse timestamp string # Parse timestamp string
from datetime import datetime 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