Add more debugging to job loading and fix sorting

- Add prints in load_jobs and save_jobs to track job persistence
- Change job sorting to use string timestamps to avoid type comparison errors
This commit is contained in:
nmemmert committed 2025-11-05 15:41:22 -05:00
1 parent 0d2384ca55
commit 99422217bf
1 file changed
+10 -3
+10 -3
View File
@@ -310,12 +310,14 @@ def cleanup_temp_files():
def load_jobs():
"""Load jobs from JSON file."""
print(f"Loading jobs from {JOBS_FILE}")
if os.path.exists(JOBS_FILE):
try:
with open(JOBS_FILE, 'r') as f:
jobs = json.load(f)
print(f"Loaded raw jobs: {list(jobs.keys())}")
# Convert timestamp strings back to datetime objects
for job in jobs.values():
for job_id, job in jobs.items():
if 'timestamp' in job and isinstance(job['timestamp'], str):
try:
# Handle the format: "2025-11-05 09:10:23.730974"
@@ -323,13 +325,18 @@ def load_jobs():
except (ValueError, TypeError):
# If conversion fails, keep as string
pass
print(f"Processed {len(jobs)} jobs")
return jobs
except:
except Exception as e:
print(f"Error loading jobs: {e}")
return {}
else:
print("Jobs file does not exist")
return {}
def save_jobs(jobs):
"""Save jobs to JSON file."""
print(f"Saving {len(jobs)} jobs to {JOBS_FILE}")
with open(JOBS_FILE, 'w') as f:
json.dump(jobs, f, indent=2, default=str)
@@ -427,7 +434,7 @@ def jobs():
jobs = load_jobs()
print(f"Loaded {len(jobs)} jobs")
# Sort jobs by timestamp, newest first
sorted_jobs = sorted(jobs.values(), key=lambda x: x['timestamp'], reverse=True)
sorted_jobs = sorted(jobs.values(), key=lambda x: str(x.get('timestamp', '')), reverse=True)
return render_template('jobs.html', jobs=sorted_jobs, user_info=get_user_info())
@app.route('/job/<job_id>')