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'))
|
||||
|
||||
# Job storage
|
||||
JOBS_FILE = 'jobs.json'
|
||||
JOBS_FILE = os.path.join(os.path.dirname(__file__), 'jobs.json')
|
||||
RESULTS_DIR = 'results'
|
||||
os.makedirs(RESULTS_DIR, exist_ok=True)
|
||||
|
||||
@@ -385,11 +385,13 @@ def index():
|
||||
'progress': 0
|
||||
}
|
||||
save_jobs(jobs)
|
||||
print(f"Job {job_id} created and saved")
|
||||
|
||||
# Start processing in background
|
||||
processing_complete = False
|
||||
thread = threading.Thread(target=process_pdfs_async, args=(input_dir, output_dir, job_id))
|
||||
thread.start()
|
||||
print(f"Thread started for job {job_id}")
|
||||
|
||||
# Redirect to job status page
|
||||
return redirect(url_for('job_status', job_id=job_id))
|
||||
@@ -423,6 +425,7 @@ def results():
|
||||
@login_required
|
||||
def jobs():
|
||||
jobs = load_jobs()
|
||||
print(f"Loaded {len(jobs)} jobs")
|
||||
# Sort jobs by timestamp, newest first
|
||||
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())
|
||||
@@ -666,9 +669,11 @@ def process_pdfs(pdfdir, outputfolder, job_id=None):
|
||||
|
||||
def process_pdfs_async(pdfdir, outputfolder, job_id):
|
||||
global processing_complete
|
||||
print(f"Processing started for job {job_id}")
|
||||
try:
|
||||
jobs = load_jobs()
|
||||
if job_id not in jobs:
|
||||
print(f"Job {job_id} not found in jobs")
|
||||
return
|
||||
|
||||
status_file = 'status.txt'
|
||||
@@ -721,9 +726,11 @@ def process_pdfs_async(pdfdir, outputfolder, job_id):
|
||||
time.sleep(0.1)
|
||||
|
||||
# Parallel processing
|
||||
num_processes = min(cpu_count(), len(pdf_files))
|
||||
with Pool(processes=num_processes) as pool:
|
||||
results = pool.map(process_single_pdf, pdf_files)
|
||||
print(f"Processing {len(pdf_files)} files sequentially")
|
||||
results = []
|
||||
for pdf_file in pdf_files:
|
||||
result = process_single_pdf(pdf_file)
|
||||
results.append(result)
|
||||
|
||||
# Process results sequentially
|
||||
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]['progress'] = 100
|
||||
save_jobs(jobs)
|
||||
print(f"Job {job_id} completed successfully")
|
||||
|
||||
msg = f"ZIP created: {zip_filename}\n"
|
||||
with open(status_file, 'a') as status_f:
|
||||
@@ -895,6 +903,7 @@ def process_pdfs_async(pdfdir, outputfolder, job_id):
|
||||
save_jobs(jobs)
|
||||
|
||||
except Exception as e:
|
||||
print(f"Processing failed for job {job_id}: {e}")
|
||||
msg = f"Processing error: {e}"
|
||||
with open('status.txt', 'w') as f:
|
||||
f.write(msg)
|
||||
|
||||
Binary file not shown.
Reference in new issue
Block a user