nopaque/web/app/tasks/__init__.py

37 lines
1.4 KiB
Python
Raw Normal View History

2020-11-09 15:14:19 +00:00
from .. import db
from ..models import Corpus, Job
import docker
docker_client = docker.from_env()
from . import corpus_utils, job_utils # noqa
def check_corpora():
corpora = Corpus.query.all()
for corpus in filter(lambda corpus: corpus.status == 'submitted', corpora):
corpus_utils.create_build_corpus_service(corpus)
for corpus in filter(lambda corpus: corpus.status in ['queued', 'running'], corpora): # noqa
2020-11-09 15:14:19 +00:00
corpus_utils.checkout_build_corpus_service(corpus)
for corpus in filter(lambda corpus: corpus.status == 'start analysis', corpora): # noqa
2020-11-09 15:14:19 +00:00
corpus_utils.create_cqpserver_container(corpus)
for corpus in filter(lambda corpus: corpus.status == 'stop analysis', corpora): # noqa
2020-11-09 15:14:19 +00:00
corpus_utils.remove_cqpserver_container(corpus)
db.session.commit()
def check_jobs():
2020-11-13 12:33:32 +00:00
print('check_jobs()')
2020-11-09 15:14:19 +00:00
jobs = Job.query.all()
2020-11-13 12:33:32 +00:00
print([job.status for job in jobs])
2020-11-09 15:14:19 +00:00
for job in filter(lambda job: job.status == 'submitted', jobs):
2020-11-13 12:33:32 +00:00
print('pre create_job_service({})'.format(job))
2020-11-09 15:14:19 +00:00
job_utils.create_job_service(job)
for job in filter(lambda job: job.status in ['queued', 'running'], jobs):
2020-11-13 12:33:32 +00:00
print('pre checkout_job_service({})'.format(job))
2020-11-09 15:14:19 +00:00
job_utils.checkout_job_service(job)
2020-11-13 12:33:32 +00:00
for job in filter(lambda job: job.status == 'canceling', jobs):
print('pre remove_job_service({})'.format(job))
job_utils.remove_job_service(job)
2020-11-09 15:14:19 +00:00
db.session.commit()