Add extensive debug logging to delete_job endpoint
This commit is contained in:
1 parent
e0cf5146df
commit
1e39888e29
1 file changed
+30
-5
+30
-5
@@ -1397,46 +1397,71 @@ def download(filename):
|
|||||||
@app.route('/delete/<job_id>', methods=['POST'])
|
@app.route('/delete/<job_id>', methods=['POST'])
|
||||||
@login_required
|
@login_required
|
||||||
def delete_job(job_id):
|
def delete_job(job_id):
|
||||||
|
import sys
|
||||||
|
print(f"DEBUG: delete_job called for job_id: {job_id}", file=sys.stderr, flush=True)
|
||||||
|
print(f"DEBUG: delete_job called for job_id: {job_id}", flush=True)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
print(f"DEBUG: Acquiring job_lock", file=sys.stderr, flush=True)
|
||||||
with job_lock:
|
with job_lock:
|
||||||
|
print(f"DEBUG: Lock acquired, checking if job exists", file=sys.stderr, flush=True)
|
||||||
if job_id in job_queue:
|
if job_id in job_queue:
|
||||||
job = job_queue[job_id]
|
job = job_queue[job_id]
|
||||||
|
print(f"DEBUG: Job found with status: {job.get('status')}", file=sys.stderr, flush=True)
|
||||||
|
|
||||||
# Only allow deletion of completed jobs
|
# Only allow deletion of completed jobs
|
||||||
if job.get('status') == 'completed':
|
if job.get('status') == 'completed':
|
||||||
|
print(f"DEBUG: Job is completed, proceeding with deletion", file=sys.stderr, flush=True)
|
||||||
|
|
||||||
# Clean up the ZIP file from archives folder
|
# Clean up the ZIP file from archives folder
|
||||||
if job.get('zip_name'):
|
if job.get('zip_name'):
|
||||||
|
print(f"DEBUG: ARCHIVE_FOLDER config: {app.config.get('ARCHIVE_FOLDER')}", file=sys.stderr, flush=True)
|
||||||
zip_path = os.path.join(app.config['ARCHIVE_FOLDER'], job['zip_name'])
|
zip_path = os.path.join(app.config['ARCHIVE_FOLDER'], job['zip_name'])
|
||||||
|
print(f"DEBUG: Attempting to delete ZIP at: {zip_path}", file=sys.stderr, flush=True)
|
||||||
if os.path.exists(zip_path):
|
if os.path.exists(zip_path):
|
||||||
try:
|
try:
|
||||||
os.remove(zip_path)
|
os.remove(zip_path)
|
||||||
print(f"DEBUG: Deleted archive file: {zip_path}")
|
print(f"DEBUG: Deleted archive file: {zip_path}", file=sys.stderr, flush=True)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"ERROR: Failed to delete archive: {e}")
|
print(f"ERROR: Failed to delete archive: {e}", file=sys.stderr, flush=True)
|
||||||
|
import traceback
|
||||||
|
traceback.print_exc()
|
||||||
flash('Job deleted but archive file could not be removed.', 'warning')
|
flash('Job deleted but archive file could not be removed.', 'warning')
|
||||||
|
else:
|
||||||
|
print(f"DEBUG: ZIP file does not exist: {zip_path}", file=sys.stderr, flush=True)
|
||||||
|
|
||||||
# Clean up any remaining uploaded files
|
# Clean up any remaining uploaded files
|
||||||
|
print(f"DEBUG: Cleaning up {len(job.get('files', []))} uploaded files", file=sys.stderr, flush=True)
|
||||||
for file_info in job.get('files', []):
|
for file_info in job.get('files', []):
|
||||||
if 'path' in file_info and os.path.exists(file_info['path']):
|
if 'path' in file_info and os.path.exists(file_info['path']):
|
||||||
try:
|
try:
|
||||||
os.remove(file_info['path'])
|
os.remove(file_info['path'])
|
||||||
print(f"DEBUG: Deleted uploaded file: {file_info['path']}")
|
print(f"DEBUG: Deleted uploaded file: {file_info['path']}", file=sys.stderr, flush=True)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"ERROR: Failed to delete uploaded file: {e}")
|
print(f"ERROR: Failed to delete uploaded file: {e}", file=sys.stderr, flush=True)
|
||||||
|
|
||||||
# Remove the job from the queue
|
# Remove the job from the queue
|
||||||
|
print(f"DEBUG: Removing job from queue", file=sys.stderr, flush=True)
|
||||||
del job_queue[job_id]
|
del job_queue[job_id]
|
||||||
|
print(f"DEBUG: Saving jobs to disk", file=sys.stderr, flush=True)
|
||||||
save_jobs() # Persist job deletion
|
save_jobs() # Persist job deletion
|
||||||
|
print(f"DEBUG: Job deletion complete, setting flash message", file=sys.stderr, flush=True)
|
||||||
flash('Job deleted successfully.', 'success')
|
flash('Job deleted successfully.', 'success')
|
||||||
else:
|
else:
|
||||||
|
print(f"DEBUG: Job status is not completed: {job.get('status')}", file=sys.stderr, flush=True)
|
||||||
flash('Only completed jobs can be deleted.', 'error')
|
flash('Only completed jobs can be deleted.', 'error')
|
||||||
else:
|
else:
|
||||||
|
print(f"DEBUG: Job not found in queue", file=sys.stderr, flush=True)
|
||||||
flash('Job not found.', 'error')
|
flash('Job not found.', 'error')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"ERROR: Exception in delete_job: {e}")
|
print(f"ERROR: Exception in delete_job: {e}", file=sys.stderr, flush=True)
|
||||||
|
print(f"ERROR: Exception in delete_job: {e}", flush=True)
|
||||||
import traceback
|
import traceback
|
||||||
|
traceback.print_exc(file=sys.stderr)
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
flash(f'Error deleting job: {str(e)}', 'error')
|
flash(f'Error deleting job: {str(e)}', 'error')
|
||||||
|
|
||||||
|
print(f"DEBUG: Redirecting to /jobs", file=sys.stderr, flush=True)
|
||||||
return redirect('/jobs')
|
return redirect('/jobs')
|
||||||
|
|
||||||
@app.route('/completed-jobs')
|
@app.route('/completed-jobs')
|
||||||
|
|||||||
Reference in new issue
Block a user