use job id for swarm run instead of job object

This commit is contained in:
Patrick Jentsch 2019-08-11 19:01:19 +02:00
parent a302d08405
commit ad8a8a4696
2 changed files with 8 additions and 7 deletions

View File

@ -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'))

View File

@ -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()