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:
1 parent
0d2384ca55
commit
99422217bf
1 file changed
+10
-3
@@ -310,12 +310,14 @@ def cleanup_temp_files():
|
|||||||
|
|
||||||
def load_jobs():
|
def load_jobs():
|
||||||
"""Load jobs from JSON file."""
|
"""Load jobs from JSON file."""
|
||||||
|
print(f"Loading jobs from {JOBS_FILE}")
|
||||||
if os.path.exists(JOBS_FILE):
|
if os.path.exists(JOBS_FILE):
|
||||||
try:
|
try:
|
||||||
with open(JOBS_FILE, 'r') as f:
|
with open(JOBS_FILE, 'r') as f:
|
||||||
jobs = json.load(f)
|
jobs = json.load(f)
|
||||||
|
print(f"Loaded raw jobs: {list(jobs.keys())}")
|
||||||
# Convert timestamp strings back to datetime objects
|
# 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):
|
if 'timestamp' in job and isinstance(job['timestamp'], str):
|
||||||
try:
|
try:
|
||||||
# Handle the format: "2025-11-05 09:10:23.730974"
|
# Handle the format: "2025-11-05 09:10:23.730974"
|
||||||
@@ -323,13 +325,18 @@ def load_jobs():
|
|||||||
except (ValueError, TypeError):
|
except (ValueError, TypeError):
|
||||||
# If conversion fails, keep as string
|
# If conversion fails, keep as string
|
||||||
pass
|
pass
|
||||||
|
print(f"Processed {len(jobs)} jobs")
|
||||||
return jobs
|
return jobs
|
||||||
except:
|
except Exception as e:
|
||||||
|
print(f"Error loading jobs: {e}")
|
||||||
return {}
|
return {}
|
||||||
|
else:
|
||||||
|
print("Jobs file does not exist")
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
def save_jobs(jobs):
|
def save_jobs(jobs):
|
||||||
"""Save jobs to JSON file."""
|
"""Save jobs to JSON file."""
|
||||||
|
print(f"Saving {len(jobs)} jobs to {JOBS_FILE}")
|
||||||
with open(JOBS_FILE, 'w') as f:
|
with open(JOBS_FILE, 'w') as f:
|
||||||
json.dump(jobs, f, indent=2, default=str)
|
json.dump(jobs, f, indent=2, default=str)
|
||||||
|
|
||||||
@@ -427,7 +434,7 @@ def jobs():
|
|||||||
jobs = load_jobs()
|
jobs = load_jobs()
|
||||||
print(f"Loaded {len(jobs)} jobs")
|
print(f"Loaded {len(jobs)} jobs")
|
||||||
# Sort jobs by timestamp, newest first
|
# 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())
|
return render_template('jobs.html', jobs=sorted_jobs, user_info=get_user_info())
|
||||||
|
|
||||||
@app.route('/job/<job_id>')
|
@app.route('/job/<job_id>')
|
||||||
|
|||||||
Reference in new issue
Block a user