mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-11-15 01:05:42 +00:00
Move sheduler start logic
This commit is contained in:
parent
158190de1a
commit
94548ac30c
@ -2,7 +2,9 @@ from flask import current_app
|
|||||||
from flask_migrate import upgrade
|
from flask_migrate import upgrade
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import List
|
from typing import List
|
||||||
|
from app import db
|
||||||
from app.models import (
|
from app.models import (
|
||||||
|
Corpus,
|
||||||
CorpusFollowerRole,
|
CorpusFollowerRole,
|
||||||
Role,
|
Role,
|
||||||
SpaCyNLPPipelineModel,
|
SpaCyNLPPipelineModel,
|
||||||
@ -15,10 +17,11 @@ from . import bp
|
|||||||
@bp.cli.command('deploy')
|
@bp.cli.command('deploy')
|
||||||
def deploy():
|
def deploy():
|
||||||
''' Run deployment tasks. '''
|
''' Run deployment tasks. '''
|
||||||
# Make default directories
|
|
||||||
print('Make default directories')
|
print('Make default directories')
|
||||||
base_dir = current_app.config['NOPAQUE_DATA_DIR']
|
base_dir = current_app.config['NOPAQUE_DATA_DIR']
|
||||||
default_dirs: List[Path] = [
|
default_dirs: List[Path] = [
|
||||||
|
Path('/var/log/nopaque'),
|
||||||
base_dir / 'tmp',
|
base_dir / 'tmp',
|
||||||
base_dir / 'users'
|
base_dir / 'users'
|
||||||
]
|
]
|
||||||
@ -28,11 +31,9 @@ def deploy():
|
|||||||
if not default_dir.is_dir():
|
if not default_dir.is_dir():
|
||||||
raise NotADirectoryError(f'{default_dir} is not a directory')
|
raise NotADirectoryError(f'{default_dir} is not a directory')
|
||||||
|
|
||||||
# migrate database to latest revision
|
|
||||||
print('Migrate database to latest revision')
|
print('Migrate database to latest revision')
|
||||||
upgrade()
|
upgrade()
|
||||||
|
|
||||||
# Insert/Update default database values
|
|
||||||
print('Insert/Update default Roles')
|
print('Insert/Update default Roles')
|
||||||
Role.insert_defaults()
|
Role.insert_defaults()
|
||||||
print('Insert/Update default Users')
|
print('Insert/Update default Users')
|
||||||
@ -44,4 +45,9 @@ def deploy():
|
|||||||
print('Insert/Update default TesseractOCRPipelineModels')
|
print('Insert/Update default TesseractOCRPipelineModels')
|
||||||
TesseractOCRPipelineModel.insert_defaults()
|
TesseractOCRPipelineModel.insert_defaults()
|
||||||
|
|
||||||
|
print('Stop running analysis sessions')
|
||||||
|
for corpus in Corpus.query.filter(Corpus.num_analysis_sessions > 0).all():
|
||||||
|
corpus.num_analysis_sessions = 0
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
# TODO: Implement checks for if the nopaque network exists
|
# TODO: Implement checks for if the nopaque network exists
|
||||||
|
23
wsgi.py
23
wsgi.py
@ -8,20 +8,6 @@ from flask import Flask # noqa
|
|||||||
from typing import Any, Dict # noqa
|
from typing import Any, Dict # noqa
|
||||||
from app import create_app, db, scheduler, socketio # noqa
|
from app import create_app, db, scheduler, socketio # noqa
|
||||||
from app import models # noqa
|
from app import models # noqa
|
||||||
# from app.models import (
|
|
||||||
# Avatar,
|
|
||||||
# Corpus,
|
|
||||||
# CorpusFile,
|
|
||||||
# CorpusFollowerAssociation,
|
|
||||||
# CorpusFollowerRole,
|
|
||||||
# Job,
|
|
||||||
# JobInput,
|
|
||||||
# JobResult,
|
|
||||||
# Role,
|
|
||||||
# TesseractOCRPipelineModel,
|
|
||||||
# SpaCyNLPPipelineModel,
|
|
||||||
# User
|
|
||||||
# ) # noqa
|
|
||||||
|
|
||||||
|
|
||||||
app: Flask = create_app()
|
app: Flask = create_app()
|
||||||
@ -48,12 +34,9 @@ def make_shell_context() -> Dict[str, Any]:
|
|||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
with app.app_context():
|
if app.config['NOPAQUE_IS_PRIMARY_INSTANCE']:
|
||||||
if app.config['NOPAQUE_IS_PRIMARY_INSTANCE']:
|
with app.app_context():
|
||||||
for corpus in models.Corpus.query.filter(models.Corpus.num_analysis_sessions > 0).all():
|
scheduler.start()
|
||||||
corpus.num_analysis_sessions = 0
|
|
||||||
db.session.commit()
|
|
||||||
scheduler.start()
|
|
||||||
socketio.run(app, host='0.0.0.0')
|
socketio.run(app, host='0.0.0.0')
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user