Add debugging prints and switch to sequential processing
- Add print statements to track job creation, processing start, completion, and failures - Use absolute path for jobs.json to avoid working directory issues - Temporarily switch to sequential PDF processing to avoid multiprocessing issues on remote server
This commit is contained in:
1 parent
1d89e1ca36
commit
0d2384ca55
2 files changed
+13
-4
No files matched your search
@@ -269,7 +269,7 @@ def logout():
|
|||||||
return redirect(url_for('index'))
|
return redirect(url_for('index'))
|
||||||
|
|
||||||
# Job storage
|
# Job storage
|
||||||
JOBS_FILE = 'jobs.json'
|
JOBS_FILE = os.path.join(os.path.dirname(__file__), 'jobs.json')
|
||||||
RESULTS_DIR = 'results'
|
RESULTS_DIR = 'results'
|
||||||
os.makedirs(RESULTS_DIR, exist_ok=True)
|
os.makedirs(RESULTS_DIR, exist_ok=True)
|
||||||
|
|
||||||
@@ -385,11 +385,13 @@ def index():
|
|||||||
'progress': 0
|
'progress': 0
|
||||||
}
|
}
|
||||||
save_jobs(jobs)
|
save_jobs(jobs)
|
||||||
|
print(f"Job {job_id} created and saved")
|
||||||
|
|
||||||
# Start processing in background
|
# Start processing in background
|
||||||
processing_complete = False
|
processing_complete = False
|
||||||
thread = threading.Thread(target=process_pdfs_async, args=(input_dir, output_dir, job_id))
|
thread = threading.Thread(target=process_pdfs_async, args=(input_dir, output_dir, job_id))
|
||||||
thread.start()
|
thread.start()
|
||||||
|
print(f"Thread started for job {job_id}")
|
||||||
|
|
||||||
# Redirect to job status page
|
# Redirect to job status page
|
||||||
return redirect(url_for('job_status', job_id=job_id))
|
return redirect(url_for('job_status', job_id=job_id))
|
||||||
@@ -423,6 +425,7 @@ def results():
|
|||||||
@login_required
|
@login_required
|
||||||
def jobs():
|
def jobs():
|
||||||
jobs = load_jobs()
|
jobs = load_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: x['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())
|
||||||
@@ -666,9 +669,11 @@ def process_pdfs(pdfdir, outputfolder, job_id=None):
|
|||||||
|
|
||||||
def process_pdfs_async(pdfdir, outputfolder, job_id):
|
def process_pdfs_async(pdfdir, outputfolder, job_id):
|
||||||
global processing_complete
|
global processing_complete
|
||||||
|
print(f"Processing started for job {job_id}")
|
||||||
try:
|
try:
|
||||||
jobs = load_jobs()
|
jobs = load_jobs()
|
||||||
if job_id not in jobs:
|
if job_id not in jobs:
|
||||||
|
print(f"Job {job_id} not found in jobs")
|
||||||
return
|
return
|
||||||
|
|
||||||
status_file = 'status.txt'
|
status_file = 'status.txt'
|
||||||
@@ -721,9 +726,11 @@ def process_pdfs_async(pdfdir, outputfolder, job_id):
|
|||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
|
|
||||||
# Parallel processing
|
# Parallel processing
|
||||||
num_processes = min(cpu_count(), len(pdf_files))
|
print(f"Processing {len(pdf_files)} files sequentially")
|
||||||
with Pool(processes=num_processes) as pool:
|
results = []
|
||||||
results = pool.map(process_single_pdf, pdf_files)
|
for pdf_file in pdf_files:
|
||||||
|
result = process_single_pdf(pdf_file)
|
||||||
|
results.append(result)
|
||||||
|
|
||||||
# Process results sequentially
|
# Process results sequentially
|
||||||
with open(os.path.join(addresses_dir, 'Addresses.csv'), 'w') as addr_csv:
|
with open(os.path.join(addresses_dir, 'Addresses.csv'), 'w') as addr_csv:
|
||||||
@@ -876,6 +883,7 @@ def process_pdfs_async(pdfdir, outputfolder, job_id):
|
|||||||
jobs[job_id]['message'] = f'Processing complete! ZIP created: {zip_filename}'
|
jobs[job_id]['message'] = f'Processing complete! ZIP created: {zip_filename}'
|
||||||
jobs[job_id]['progress'] = 100
|
jobs[job_id]['progress'] = 100
|
||||||
save_jobs(jobs)
|
save_jobs(jobs)
|
||||||
|
print(f"Job {job_id} completed successfully")
|
||||||
|
|
||||||
msg = f"ZIP created: {zip_filename}\n"
|
msg = f"ZIP created: {zip_filename}\n"
|
||||||
with open(status_file, 'a') as status_f:
|
with open(status_file, 'a') as status_f:
|
||||||
@@ -895,6 +903,7 @@ def process_pdfs_async(pdfdir, outputfolder, job_id):
|
|||||||
save_jobs(jobs)
|
save_jobs(jobs)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
print(f"Processing failed for job {job_id}: {e}")
|
||||||
msg = f"Processing error: {e}"
|
msg = f"Processing error: {e}"
|
||||||
with open('status.txt', 'w') as f:
|
with open('status.txt', 'w') as f:
|
||||||
f.write(msg)
|
f.write(msg)
|
||||||
|
|||||||
Binary file not shown.
Reference in new issue
Block a user