nopaque/web/app/daemon.py

44 lines
1.4 KiB
Python
Raw Normal View History

2020-11-06 14:07:58 +00:00
from app import create_app
from time import sleep
from ..decorators import background
import docker
app = create_app()
docker_client = docker.from_env()
app.app_context().push()
from . import check_corpora, check_jobs, notify # noqa
def run():
check_corpora_thread = check_corpora()
check_jobs_thread = check_jobs()
notify_thread = notify()
while True:
if not check_corpora_thread.is_alive():
check_corpora_thread = check_corpora()
if not check_jobs_thread.is_alive():
check_jobs_thread = check_jobs()
if not notify_thread.is_alive():
notify_thread = notify()
sleep(3)
@background
def check_corpora():
corpora = Corpus.query.all()
for corpus in filter(lambda corpus: corpus.status == 'submitted', corpora):
__create_build_corpus_service(corpus)
for corpus in filter(lambda corpus: (corpus.status == 'queued'
or corpus.status == 'running'),
corpora):
__checkout_build_corpus_service(corpus)
for corpus in filter(lambda corpus: corpus.status == 'start analysis',
corpora):
__create_cqpserver_container(corpus)
for corpus in filter(lambda corpus: corpus.status == 'stop analysis',
corpora):
__remove_cqpserver_container(corpus)