Simplify job status updates API

- Return all active jobs on every poll instead of timestamp-based filtering
- Ensures status changes are always reflected in the UI
- Works with or without updated_at column in database
parent be9f88d7
...@@ -509,40 +509,14 @@ def api_job_status(job_id): ...@@ -509,40 +509,14 @@ def api_job_status(job_id):
def api_job_status_updates(): def api_job_status_updates():
"""API endpoint for job status updates.""" """API endpoint for job status updates."""
user = get_current_user_session() user = get_current_user_session()
since = request.args.get('since', '0')
try: # Get all active jobs for the user (not completed/failed)
since_timestamp = int(since) / 1000.0 # Convert from milliseconds to seconds
except ValueError:
since_timestamp = 0
# Get updated jobs since the given timestamp
queue_items = get_user_queue_items(user['id']) queue_items = get_user_queue_items(user['id'])
updates = [] updates = []
for job in queue_items: for job in queue_items:
# Convert job timestamps to comparable format (use updated_at if available, otherwise created_at) # Include all active jobs (queued, processing, cancelled)
job_time = job.get('updated_at') or job.get('created_at') if job['status'] not in ['completed', 'failed']:
if isinstance(job_time, str):
# Parse timestamp string
from datetime import datetime
try:
job_timestamp = datetime.fromisoformat(job_time.replace('Z', '+00:00')).timestamp()
except:
job_timestamp = 0
else:
job_timestamp = job_time or 0
# For jobs without updated_at, use created_at but only include if status changed recently
# Since we can't track updates, include all active jobs
include_job = False
if 'updated_at' in job and job['updated_at']:
include_job = job_timestamp > since_timestamp
else:
# For jobs without updated_at, include if they're active (not completed/failed)
include_job = job['status'] not in ['completed', 'failed']
if include_job:
updates.append({ updates.append({
'id': job['id'], 'id': job['id'],
'status': job['status'], 'status': job['status'],
......
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