Processing fix

This commit is contained in:
nmemmert committed 2025-11-07 09:33:25 -05:00
1 parent c98e89b5e4
commit 9a430e798f
6 files changed
+132 -24

No files matched your search

Binary file not shown.
+27
View File
@@ -0,0 +1,27 @@
#!/usr/bin/env python3
"""
Create a test processing job to verify progress updates
"""
import json
from pdf_renamer import job_queue, save_jobs
# Create a test processing job
test_job = {
'status': 'processing',
'files': [{'name': 'test.pdf', 'path': '/tmp/test.pdf'}],
'zip_path': None,
'zip_name': None,
'processed_files': [],
'skipped': [],
'created_at': '2025-11-07 10:00:00',
'job_id': '2025-11-07_10-00-00',
'progress': 'Test progress - should update every second'
}
job_queue['2025-11-07_10-00-00'] = test_job
save_jobs()
print('Created test processing job with progress updates')
print('Job ID: 2025-11-07_10-00-00')
print('Status: processing')
print('Progress: Test progress - should update every second')
+5 -5
View File
@@ -1,6 +1,6 @@
{ {
"2024-01-01_12-00-00": { "2025-11-07_10-00-00": {
"status": "completed", "status": "processing",
"files": [ "files": [
{ {
"name": "test.pdf", "name": "test.pdf",
@@ -11,8 +11,8 @@
"zip_name": null, "zip_name": null,
"processed_files": [], "processed_files": [],
"skipped": [], "skipped": [],
"created_at": "2024-01-01 12:00:00", "created_at": "2025-11-07 10:00:00",
"job_id": "2024-01-01_12-00-00", "job_id": "2025-11-07_10-00-00",
"progress": "Created ZIP archive with 1 organized files" "progress": "Test progress - should update every second"
} }
} }
+23 -19
View File
@@ -511,7 +511,6 @@ def process_job(job_id, files):
job_queue[job_id]['status'] = 'processing' job_queue[job_id]['status'] = 'processing'
job_queue[job_id]['progress'] = 'Starting job processing...' job_queue[job_id]['progress'] = 'Starting job processing...'
save_jobs() # Persist initial progress save_jobs() # Persist initial progress
save_jobs() # Persist status change
processed_files = [] processed_files = []
temp_extract_dirs = [] temp_extract_dirs = []
@@ -561,6 +560,7 @@ def process_job(job_id, files):
print(f"DEBUG: ZIP contains {file_count} files: {zip_ref.namelist()}") print(f"DEBUG: ZIP contains {file_count} files: {zip_ref.namelist()}")
zip_ref.extractall(extract_dir) zip_ref.extractall(extract_dir)
job_queue[job_id]['progress'] = f'Extracted {file_count} files from {filename}' job_queue[job_id]['progress'] = f'Extracted {file_count} files from {filename}'
save_jobs() # Persist ZIP extraction progress
print(f"DEBUG: ZIP extraction completed, progress updated: {job_queue[job_id]['progress']}") print(f"DEBUG: ZIP extraction completed, progress updated: {job_queue[job_id]['progress']}")
# Process PDFs in extract_dir # Process PDFs in extract_dir
@@ -571,6 +571,7 @@ def process_job(job_id, files):
pdf_files_found.append(f) pdf_files_found.append(f)
pdf_path = os.path.join(root, f) pdf_path = os.path.join(root, f)
job_queue[job_id]['progress'] = f'Processing PDF: {f}' job_queue[job_id]['progress'] = f'Processing PDF: {f}'
save_jobs() # Persist current file progress
print(f"DEBUG: Processing PDF: {f} at {pdf_path}") print(f"DEBUG: Processing PDF: {f} at {pdf_path}")
print(f"DEBUG: File exists: {os.path.exists(pdf_path)}") print(f"DEBUG: File exists: {os.path.exists(pdf_path)}")
pdf_info = extract_names_from_pdf(pdf_path) pdf_info = extract_names_from_pdf(pdf_path)
@@ -604,6 +605,7 @@ def process_job(job_id, files):
processed_files.append(('success', os.path.relpath(new_path, episode_dir), new_path)) processed_files.append(('success', os.path.relpath(new_path, episode_dir), new_path))
processed_count += 1 processed_count += 1
job_queue[job_id]['progress'] = f'Organized {processed_count}/{total_files} files' job_queue[job_id]['progress'] = f'Organized {processed_count}/{total_files} files'
save_jobs() # Persist progress update
print(f"DEBUG: Organized file {processed_count}/{total_files}") print(f"DEBUG: Organized file {processed_count}/{total_files}")
print(f"DEBUG: Found {len(pdf_files_found)} PDF files in ZIP: {pdf_files_found}") print(f"DEBUG: Found {len(pdf_files_found)} PDF files in ZIP: {pdf_files_found}")
@@ -617,6 +619,7 @@ def process_job(job_id, files):
# Single PDF # Single PDF
try: try:
job_queue[job_id]['progress'] = f'Processing PDF: {filename}' job_queue[job_id]['progress'] = f'Processing PDF: {filename}'
save_jobs() # Persist current file progress
pdf_info = extract_names_from_pdf(filepath) pdf_info = extract_names_from_pdf(filepath)
if 'error' in pdf_info: if 'error' in pdf_info:
processed_files.append(('skipped', filename, pdf_info['error'])) processed_files.append(('skipped', filename, pdf_info['error']))
@@ -640,6 +643,7 @@ def process_job(job_id, files):
processed_files.append(('success', os.path.relpath(new_filepath, episode_dir), new_filepath)) processed_files.append(('success', os.path.relpath(new_filepath, episode_dir), new_filepath))
processed_count += 1 processed_count += 1
job_queue[job_id]['progress'] = f'Organized {processed_count}/{total_files} files' job_queue[job_id]['progress'] = f'Organized {processed_count}/{total_files} files'
save_jobs() # Persist progress update
except Exception as e: except Exception as e:
processed_files.append(('skipped', filename, f'PDF processing error: {str(e)}')) processed_files.append(('skipped', filename, f'PDF processing error: {str(e)}'))
job_queue[job_id]['progress'] = f'Failed to process PDF {filename}: {str(e)}' job_queue[job_id]['progress'] = f'Failed to process PDF {filename}: {str(e)}'
@@ -1034,6 +1038,21 @@ def jobs():
// Track previous job statuses to detect completion // Track previous job statuses to detect completion
let previousJobStatuses = {}; let previousJobStatuses = {};
// Collapsible section functions
function toggleZipDetails(element) {
const details = element.nextElementSibling;
const isVisible = details.style.display === 'block';
details.style.display = isVisible ? 'none' : 'block';
element.innerHTML = element.innerHTML.replace(isVisible ? ' ▼' : ' ▶', isVisible ? ' ▶' : ' ▼');
}
function toggleSkippedDetails(element) {
const details = element.nextElementSibling;
const isVisible = details.style.display === 'block';
details.style.display = isVisible ? 'none' : 'block';
element.innerHTML = element.innerHTML.replace(isVisible ? ' ▼' : ' ▶', isVisible ? ' ▶' : ' ▼');
}
function updateJobs() { function updateJobs() {
fetch('/api/jobs', { credentials: 'same-origin' }) fetch('/api/jobs', { credentials: 'same-origin' })
.then(response => response.json()) .then(response => response.json())
@@ -1081,9 +1100,9 @@ def jobs():
}); });
// Add updated job elements // Add updated job elements
const jobs = Object.entries(data); const jobEntries = Object.entries(data);
if (jobs.length > 0) { if (jobEntries.length > 0) {
jobs.forEach(([jobId, job]) => { jobEntries.forEach(([jobId, job]) => {
const jobDiv = document.createElement('div'); const jobDiv = document.createElement('div');
jobDiv.className = 'job'; jobDiv.className = 'job';
jobDiv.innerHTML = ` jobDiv.innerHTML = `
@@ -1149,21 +1168,6 @@ def jobs():
// Initialize previous job statuses // Initialize previous job statuses
updateJobs(); // Run once immediately to populate initial statuses updateJobs(); // Run once immediately to populate initial statuses
// Collapsible section functions
function toggleZipDetails(element) {
const details = element.nextElementSibling;
const isVisible = details.style.display === 'block';
details.style.display = isVisible ? 'none' : 'block';
element.innerHTML = element.innerHTML.replace(isVisible ? ' ▼' : ' ▶', isVisible ? ' ▶' : ' ▼');
}
function toggleSkippedDetails(element) {
const details = element.nextElementSibling;
const isVisible = details.style.display === 'block';
details.style.display = isVisible ? 'none' : 'block';
element.innerHTML = element.innerHTML.replace(isVisible ? ' ▼' : ' ▶', isVisible ? ' ▶' : ' ▼');
}
</script> </script>
</body> </body>
</html> </html>
+40
View File
@@ -0,0 +1,40 @@
#!/usr/bin/env python3
"""
Simulate progress updates for testing
"""
import time
import json
from pdf_renamer import job_queue, load_jobs, save_jobs
# Load jobs
load_jobs()
job_id = '2025-11-07_10-00-00'
if job_id in job_queue:
progress_messages = [
'Starting job processing...',
'Found 3 files to process',
'Processing PDF: document1.pdf',
'Extracted data for John Doe',
'Processing PDF: document2.pdf',
'Extracted data for Jane Smith',
'Processing PDF: document3.pdf',
'Extracted data for Bob Johnson',
'Organized 1/3 files',
'Organized 2/3 files',
'Organized 3/3 files',
'Creating ZIP archive...',
'Created ZIP archive with 3 organized files'
]
print(f'Starting progress simulation for job {job_id}')
for i, progress in enumerate(progress_messages):
job_queue[job_id]['progress'] = progress
save_jobs()
print(f'Updated progress: {progress}')
if i < len(progress_messages) - 1: # Don't sleep after last message
time.sleep(2)
print('Progress simulation complete!')
else:
print(f'Job {job_id} not found')
+37
View File
@@ -0,0 +1,37 @@
#!/usr/bin/env python3
"""
Test script to verify progress updates are working
"""
import json
from pdf_renamer import job_queue, load_jobs, save_jobs
# Load current jobs
load_jobs()
print('Current jobs:')
for job_id, job in job_queue.items():
status = job.get('status', 'unknown')
progress = job.get('progress', 'none')
print(f' {job_id}: status={status}, progress="{progress}"')
# Test updating progress
if job_queue:
test_job_id = list(job_queue.keys())[0]
print(f'\nTesting progress update for job {test_job_id}')
# Update progress
job_queue[test_job_id]['progress'] = 'Test progress update - ' + str(len(job_queue))
save_jobs()
# Reload and check
job_queue.clear()
load_jobs()
updated_progress = job_queue.get(test_job_id, {}).get('progress', 'not found')
print(f'Updated progress: "{updated_progress}"')
if 'Test progress update' in updated_progress:
print('✅ Progress updates are working!')
else:
print('❌ Progress updates not working')
else:
print('No jobs found to test with')