Don't save job filtered job lists in variables. Handle service not found error.

This commit is contained in:
Patrick Jentsch 2019-08-21 08:37:10 +02:00
parent a86ae5c75c
commit be0241519d

View File

@ -10,11 +10,7 @@ def checkout_jobs():
with scheduler.app.app_context(): with scheduler.app.app_context():
client = docker.from_env() client = docker.from_env()
jobs = db.session.query(Job) jobs = db.session.query(Job)
submitted_jobs = jobs.filter_by(status='submitted').all() for job in jobs.filter_by(status='submitted').all():
foo_jobs = jobs.filter(Job.status != 'complete',
Job.status != 'failed',
Job.status != 'submitted').all()
for job in submitted_jobs:
_command = (job.service _command = (job.service
+ ' -i /files' + ' -i /files'
+ ' -o /files/output' + ' -o /files/output'
@ -65,13 +61,15 @@ def checkout_jobs():
restart_policy=_restart_policy restart_policy=_restart_policy
) )
job.status = 'scheduled' job.status = 'scheduled'
for job in foo_jobs: for job in jobs.filter(Job.status != 'complete',
''' Job.status != 'failed',
' TODO: Handle service not found error. Job.status != 'submitted').all():
''' try:
service = client.services.get(str(job.id)) service = client.services.get(str(job.id))
job.status = service.tasks()[0].get('Status').get('State') job.status = service.tasks()[0].get('Status').get('State')
if job.status == 'complete' or job.status == 'failed': if job.status == 'complete' or job.status == 'failed':
job.end_date = datetime.utcnow() job.end_date = datetime.utcnow()
service.remove() service.remove()
except docker.errors.NotFound:
job.status = 'failed'
db.session.commit() db.session.commit()