Add error handling to delete_job endpoint
This commit is contained in:
1 parent
90ed775883
commit
864197cc11
1 file changed
+37
-30
+37
-30
@@ -1379,39 +1379,46 @@ def download(filename):
|
||||
@app.route('/delete/<job_id>', methods=['POST'])
|
||||
@login_required
|
||||
def delete_job(job_id):
|
||||
with job_lock:
|
||||
if job_id in job_queue:
|
||||
job = job_queue[job_id]
|
||||
# Only allow deletion of completed jobs
|
||||
if job.get('status') == 'completed':
|
||||
# Clean up the ZIP file from archives folder
|
||||
if job.get('zip_name'):
|
||||
zip_path = os.path.join(app.config['ARCHIVE_FOLDER'], job['zip_name'])
|
||||
if os.path.exists(zip_path):
|
||||
try:
|
||||
os.remove(zip_path)
|
||||
print(f"DEBUG: Deleted archive file: {zip_path}")
|
||||
except Exception as e:
|
||||
print(f"ERROR: Failed to delete archive: {e}")
|
||||
flash('Job deleted but archive file could not be removed.', 'warning')
|
||||
try:
|
||||
with job_lock:
|
||||
if job_id in job_queue:
|
||||
job = job_queue[job_id]
|
||||
# Only allow deletion of completed jobs
|
||||
if job.get('status') == 'completed':
|
||||
# Clean up the ZIP file from archives folder
|
||||
if job.get('zip_name'):
|
||||
zip_path = os.path.join(app.config['ARCHIVE_FOLDER'], job['zip_name'])
|
||||
if os.path.exists(zip_path):
|
||||
try:
|
||||
os.remove(zip_path)
|
||||
print(f"DEBUG: Deleted archive file: {zip_path}")
|
||||
except Exception as e:
|
||||
print(f"ERROR: Failed to delete archive: {e}")
|
||||
flash('Job deleted but archive file could not be removed.', 'warning')
|
||||
|
||||
# Clean up any remaining uploaded files
|
||||
for file_info in job.get('files', []):
|
||||
if 'path' in file_info and os.path.exists(file_info['path']):
|
||||
try:
|
||||
os.remove(file_info['path'])
|
||||
print(f"DEBUG: Deleted uploaded file: {file_info['path']}")
|
||||
except Exception as e:
|
||||
print(f"ERROR: Failed to delete uploaded file: {e}")
|
||||
# Clean up any remaining uploaded files
|
||||
for file_info in job.get('files', []):
|
||||
if 'path' in file_info and os.path.exists(file_info['path']):
|
||||
try:
|
||||
os.remove(file_info['path'])
|
||||
print(f"DEBUG: Deleted uploaded file: {file_info['path']}")
|
||||
except Exception as e:
|
||||
print(f"ERROR: Failed to delete uploaded file: {e}")
|
||||
|
||||
# Remove the job from the queue
|
||||
del job_queue[job_id]
|
||||
save_jobs() # Persist job deletion
|
||||
flash('Job deleted successfully.', 'success')
|
||||
# Remove the job from the queue
|
||||
del job_queue[job_id]
|
||||
save_jobs() # Persist job deletion
|
||||
flash('Job deleted successfully.', 'success')
|
||||
else:
|
||||
flash('Only completed jobs can be deleted.', 'error')
|
||||
else:
|
||||
flash('Only completed jobs can be deleted.', 'error')
|
||||
else:
|
||||
flash('Job not found.', 'error')
|
||||
flash('Job not found.', 'error')
|
||||
except Exception as e:
|
||||
print(f"ERROR: Exception in delete_job: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
flash(f'Error deleting job: {str(e)}', 'error')
|
||||
|
||||
return redirect('/jobs')
|
||||
|
||||
@app.route('/completed-jobs')
|
||||
|
||||
Reference in new issue
Block a user