diff --git a/app/services/views.py b/app/services/views.py index cbc13644d8c2aa6e26e70a10d70c7a75e830c85f..938e7bd6249f7d41c23ac57efa3e3d32a62b2cd9 100644 --- a/app/services/views.py +++ b/app/services/views.py @@ -48,8 +48,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 = Thread(target=swarm.run, args=(nlp_job.id,)) thread.start() flash('Job created!') return redirect(url_for('services.nlp')) @@ -101,8 +100,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 = Thread(target=swarm.run, args=(ocr_job.id,)) thread.start() flash('Job created!') return redirect(url_for('services.ocr')) diff --git a/app/swarm.py b/app/swarm.py index 50f5e77cf9ae009deff4c28c279b786db1404db9..2e57c548bf54770d836f1faa04caa59e79c57753 100644 --- a/app/swarm.py +++ b/app/swarm.py @@ -30,10 +30,13 @@ class Swarm: ' ¹ https://blog.alexellis.io/containers-on-swarm/ ''' - def run(self, job): + def run(self, job_id): ''' - Input is a job object. From this the _command is built. + Input is a job id. ''' + from .models import Job + session = self.Session() + job = session.query(Job).filter_by(id=job_id).first() # Prepare argument values needed for the service creation. service_args = json.loads(job.service_args) _command = (job.service @@ -98,9 +101,9 @@ class Swarm: time.sleep(1) service.reload() ''' + ' The following is scheduler work. ' Poll the service until the job is completly executed. ''' - session = self.Session() session.add(job) job.status = 'running' session.commit()