mirror of
				https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
				synced 2025-11-03 20:02:47 +00:00 
			
		
		
		
	Remove job from database if an error occurs. Remove job object from session before thread starts.
This commit is contained in:
		@@ -15,7 +15,6 @@ import json
 | 
			
		||||
def ocr():
 | 
			
		||||
    new_ocr_job_form = NewOCRJobForm()
 | 
			
		||||
    if new_ocr_job_form.validate_on_submit():
 | 
			
		||||
        app = current_app._get_current_object()
 | 
			
		||||
        ocr_job = Job(creator=current_user._get_current_object(),
 | 
			
		||||
                      description=new_ocr_job_form.description.data,
 | 
			
		||||
                      service="ocr",
 | 
			
		||||
@@ -27,10 +26,11 @@ def ocr():
 | 
			
		||||
                                               "version": new_ocr_job_form.version.data}),
 | 
			
		||||
                      status="pending",
 | 
			
		||||
                      title=new_ocr_job_form.title.data)
 | 
			
		||||
 | 
			
		||||
        db.session.add(ocr_job)
 | 
			
		||||
        db.session.commit()
 | 
			
		||||
 | 
			
		||||
        dir = os.path.join(app.config['OPAQUE_STORAGE'],
 | 
			
		||||
        dir = os.path.join(current_app.config['OPAQUE_STORAGE'],
 | 
			
		||||
                           str(ocr_job.user_id),
 | 
			
		||||
                           'jobs',
 | 
			
		||||
                           str(ocr_job.id))
 | 
			
		||||
@@ -39,6 +39,8 @@ def ocr():
 | 
			
		||||
            os.makedirs(dir)
 | 
			
		||||
        except OSError:
 | 
			
		||||
            flash('OSError!')
 | 
			
		||||
            db.session.remove(ocr_job)
 | 
			
		||||
            db.session.commit()
 | 
			
		||||
        else:
 | 
			
		||||
            for file in new_ocr_job_form.files.data:
 | 
			
		||||
                file.save(os.path.join(dir, file.filename))
 | 
			
		||||
@@ -48,6 +50,7 @@ def ocr():
 | 
			
		||||
            ' NOTE: Using self created threads is just for testing purpose as
 | 
			
		||||
            '       there is no scheduler available.
 | 
			
		||||
            '''
 | 
			
		||||
            db.session.expunge(ocr_job)
 | 
			
		||||
            thread = Thread(target=swarm.run, args=(ocr_job,))
 | 
			
		||||
            thread.start()
 | 
			
		||||
            flash('Job created!')
 | 
			
		||||
@@ -65,7 +68,6 @@ def ocr():
 | 
			
		||||
def nlp():
 | 
			
		||||
    new_nlp_job_form = NewNLPJobForm()
 | 
			
		||||
    if new_nlp_job_form.validate_on_submit():
 | 
			
		||||
        app = current_app._get_current_object()
 | 
			
		||||
        nlp_job = Job(creator=current_user._get_current_object(),
 | 
			
		||||
                      description=new_nlp_job_form.description.data,
 | 
			
		||||
                      service="nlp",
 | 
			
		||||
@@ -76,10 +78,11 @@ def nlp():
 | 
			
		||||
                                               "version": new_nlp_job_form.version.data}),
 | 
			
		||||
                      status="pending",
 | 
			
		||||
                      title=new_nlp_job_form.title.data)
 | 
			
		||||
 | 
			
		||||
        db.session.add(nlp_job)
 | 
			
		||||
        db.session.commit()
 | 
			
		||||
 | 
			
		||||
        dir = os.path.join(app.config['OPAQUE_STORAGE'],
 | 
			
		||||
        dir = os.path.join(current_app.config['OPAQUE_STORAGE'],
 | 
			
		||||
                           str(nlp_job.user_id),
 | 
			
		||||
                           'jobs',
 | 
			
		||||
                           str(nlp_job.id))
 | 
			
		||||
@@ -88,6 +91,8 @@ def nlp():
 | 
			
		||||
            os.makedirs(dir)
 | 
			
		||||
        except OSError:
 | 
			
		||||
            flash('OSError!')
 | 
			
		||||
            db.session.remove(nlp_job)
 | 
			
		||||
            db.session.commit()
 | 
			
		||||
        else:
 | 
			
		||||
            for file in new_nlp_job_form.files.data:
 | 
			
		||||
                file.save(os.path.join(dir, file.filename))
 | 
			
		||||
@@ -97,6 +102,7 @@ def nlp():
 | 
			
		||||
            ' NOTE: Using self created threads is just for testing purpose as
 | 
			
		||||
            '       there is no scheduler available.
 | 
			
		||||
            '''
 | 
			
		||||
            db.session.expunge(nlp_job)
 | 
			
		||||
            thread = Thread(target=swarm.run, args=(nlp_job,))
 | 
			
		||||
            thread.start()
 | 
			
		||||
            flash('Job created!')
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user