Skip to content
Snippets Groups Projects
Commit ad8a8a46 authored by Patrick Jentsch's avatar Patrick Jentsch
Browse files

use job id for swarm run instead of job object

parent a302d084
No related branches found
No related tags found
No related merge requests found
...@@ -48,8 +48,7 @@ def nlp(): ...@@ -48,8 +48,7 @@ def nlp():
' NOTE: Using self created threads is just for testing purpose as ' NOTE: Using self created threads is just for testing purpose as
' there is no scheduler available. ' there is no scheduler available.
''' '''
db.session.expunge(nlp_job) thread = Thread(target=swarm.run, args=(nlp_job.id,))
thread = Thread(target=swarm.run, args=(nlp_job,))
thread.start() thread.start()
flash('Job created!') flash('Job created!')
return redirect(url_for('services.nlp')) return redirect(url_for('services.nlp'))
...@@ -101,8 +100,7 @@ def ocr(): ...@@ -101,8 +100,7 @@ def ocr():
' NOTE: Using self created threads is just for testing purpose as ' NOTE: Using self created threads is just for testing purpose as
' there is no scheduler available. ' there is no scheduler available.
''' '''
db.session.expunge(ocr_job) thread = Thread(target=swarm.run, args=(ocr_job.id,))
thread = Thread(target=swarm.run, args=(ocr_job,))
thread.start() thread.start()
flash('Job created!') flash('Job created!')
return redirect(url_for('services.ocr')) return redirect(url_for('services.ocr'))
......
...@@ -30,10 +30,13 @@ class Swarm: ...@@ -30,10 +30,13 @@ class Swarm:
' ¹ https://blog.alexellis.io/containers-on-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. # Prepare argument values needed for the service creation.
service_args = json.loads(job.service_args) service_args = json.loads(job.service_args)
_command = (job.service _command = (job.service
...@@ -98,9 +101,9 @@ class Swarm: ...@@ -98,9 +101,9 @@ class Swarm:
time.sleep(1) time.sleep(1)
service.reload() service.reload()
''' '''
' The following is scheduler work.
' Poll the service until the job is completly executed. ' Poll the service until the job is completly executed.
''' '''
session = self.Session()
session.add(job) session.add(job)
job.status = 'running' job.status = 'running'
session.commit() session.commit()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment