From 168052ed0c3e600a1e62665e2e7a7c33f7f54623 Mon Sep 17 00:00:00 2001 From: nmemmert <67961292+nmemmert@users.noreply.github.com> Date: Fri, 7 Nov 2025 10:03:47 -0500 Subject: [PATCH] Fix: Validate archive files exist when loading jobs on startup --- pdf_renamer.py | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/pdf_renamer.py b/pdf_renamer.py index bd33f40..322e7de 100644 --- a/pdf_renamer.py +++ b/pdf_renamer.py @@ -92,8 +92,34 @@ def load_jobs(): if os.path.exists(JOBS_FILE): with open(JOBS_FILE, 'r') as 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: print("DEBUG: No existing jobs file found, starting fresh") except Exception as e: