mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-11-15 01:05:42 +00:00
Make the "daemon" (now tasks) more understandable
This commit is contained in:
parent
aabea234fe
commit
5f05cedf5e
@ -141,8 +141,11 @@ def create_app(config: Config = Config) -> Flask:
|
||||
|
||||
# region Add scheduler jobs
|
||||
if app.config['NOPAQUE_IS_PRIMARY_INSTANCE']:
|
||||
from .daemon import daemon
|
||||
scheduler.add_job('daemon', daemon, args=(app,), seconds=3, trigger='interval')
|
||||
from .tasks import handle_corpora
|
||||
scheduler.add_job('handle_corpora', handle_corpora, seconds=3, trigger='interval')
|
||||
|
||||
from .tasks import handle_jobs
|
||||
scheduler.add_job('handle_jobs', handle_jobs, seconds=3, trigger='interval')
|
||||
# endregion Add scheduler jobs
|
||||
|
||||
return app
|
||||
|
@ -1,11 +0,0 @@
|
||||
from flask import Flask
|
||||
from app import db
|
||||
from .corpus_utils import check_corpora
|
||||
from .job_utils import check_jobs
|
||||
|
||||
|
||||
def daemon(app: Flask):
|
||||
with app.app_context():
|
||||
check_corpora()
|
||||
check_jobs()
|
||||
db.session.commit()
|
2
app/tasks/__init__.py
Normal file
2
app/tasks/__init__.py
Normal file
@ -0,0 +1,2 @@
|
||||
from .handle_corpora import task as handle_corpora
|
||||
from .handle_jobs import task as handle_jobs
|
@ -1,4 +1,4 @@
|
||||
from app import docker_client
|
||||
from app import db, docker_client, scheduler
|
||||
from app.models import Corpus, CorpusStatus
|
||||
from flask import current_app
|
||||
import docker
|
||||
@ -6,7 +6,11 @@ import os
|
||||
import shutil
|
||||
|
||||
|
||||
def check_corpora():
|
||||
def task():
|
||||
with scheduler.app.app_context():
|
||||
handle_corpora()
|
||||
|
||||
def handle_corpora():
|
||||
corpora = Corpus.query.all()
|
||||
for corpus in [x for x in corpora if x.status == CorpusStatus.SUBMITTED]:
|
||||
_create_build_corpus_service(corpus)
|
||||
@ -22,6 +26,7 @@ def check_corpora():
|
||||
_create_cqpserver_container(corpus)
|
||||
for corpus in [x for x in corpora if x.status == CorpusStatus.CANCELING_ANALYSIS_SESSION]:
|
||||
_remove_cqpserver_container(corpus)
|
||||
db.session.commit()
|
||||
|
||||
def _create_build_corpus_service(corpus):
|
||||
''' # Docker service settings # '''
|
@ -1,4 +1,4 @@
|
||||
from app import db, docker_client, hashids
|
||||
from app import db, docker_client, hashids, scheduler
|
||||
from app.models import (
|
||||
Job,
|
||||
JobResult,
|
||||
@ -15,7 +15,11 @@ import os
|
||||
import shutil
|
||||
|
||||
|
||||
def check_jobs():
|
||||
def task():
|
||||
with scheduler.app.app_context():
|
||||
handle_jobs()
|
||||
|
||||
def handle_jobs():
|
||||
jobs = Job.query.all()
|
||||
for job in [x for x in jobs if x.status == JobStatus.SUBMITTED]:
|
||||
_create_job_service(job)
|
||||
@ -23,6 +27,7 @@ def check_jobs():
|
||||
_checkout_job_service(job)
|
||||
for job in [x for x in jobs if x.status == JobStatus.CANCELING]:
|
||||
_remove_job_service(job)
|
||||
db.session.commit()
|
||||
|
||||
def _create_job_service(job):
|
||||
''' # Docker service settings # '''
|
Loading…
Reference in New Issue
Block a user