Fix: Validate archive files exist when loading jobs on startup
This commit is contained in:
1 parent
f3039c858c
commit
168052ed0c
1 file changed
+28
-2
+28
-2
@@ -92,8 +92,34 @@ def load_jobs():
|
|||||||
if os.path.exists(JOBS_FILE):
|
if os.path.exists(JOBS_FILE):
|
||||||
with open(JOBS_FILE, 'r') as f:
|
with open(JOBS_FILE, 'r') as f:
|
||||||
loaded_jobs = json.load(f)
|
loaded_jobs = json.load(f)
|
||||||
job_queue = loaded_jobs
|
|
||||||
print(f"DEBUG: Loaded {len(job_queue)} jobs from persistent storage")
|
# Only load jobs where archive files still exist
|
||||||
|
valid_jobs = {}
|
||||||
|
skipped_count = 0
|
||||||
|
|
||||||
|
for job_id, job_data in loaded_jobs.items():
|
||||||
|
# Only keep completed jobs with existing archive files
|
||||||
|
if job_data.get('status') == 'completed':
|
||||||
|
zip_path = job_data.get('zip_path', '')
|
||||||
|
if zip_path and os.path.exists(zip_path):
|
||||||
|
valid_jobs[job_id] = job_data
|
||||||
|
else:
|
||||||
|
skipped_count += 1
|
||||||
|
print(f"DEBUG: Skipping job {job_id} - archive file missing: {zip_path}")
|
||||||
|
# Skip jobs that were in progress (they failed during restart)
|
||||||
|
elif job_data.get('status') in ['pending', 'processing']:
|
||||||
|
skipped_count += 1
|
||||||
|
print(f"DEBUG: Skipping incomplete job {job_id} - status: {job_data.get('status')}")
|
||||||
|
# Keep error state jobs for visibility
|
||||||
|
elif job_data.get('status') == 'error':
|
||||||
|
valid_jobs[job_id] = job_data
|
||||||
|
|
||||||
|
job_queue = valid_jobs
|
||||||
|
print(f"DEBUG: Loaded {len(job_queue)} jobs from persistent storage ({skipped_count} skipped)")
|
||||||
|
|
||||||
|
# Save the cleaned up job list back to disk
|
||||||
|
if skipped_count > 0:
|
||||||
|
save_jobs()
|
||||||
else:
|
else:
|
||||||
print("DEBUG: No existing jobs file found, starting fresh")
|
print("DEBUG: No existing jobs file found, starting fresh")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
|||||||
Reference in new issue
Block a user