mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-12-25 10:54:18 +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 pathlib import Path
|
||||
from typing import List
|
||||
from app import db
|
||||
from app.models import (
|
||||
Corpus,
|
||||
CorpusFollowerRole,
|
||||
Role,
|
||||
SpaCyNLPPipelineModel,
|
||||
@ -15,10 +17,11 @@ from . import bp
|
||||
@bp.cli.command('deploy')
|
||||
def deploy():
|
||||
''' Run deployment tasks. '''
|
||||
# Make default directories
|
||||
|
||||
print('Make default directories')
|
||||
base_dir = current_app.config['NOPAQUE_DATA_DIR']
|
||||
default_dirs: List[Path] = [
|
||||
Path('/var/log/nopaque'),
|
||||
base_dir / 'tmp',
|
||||
base_dir / 'users'
|
||||
]
|
||||
@ -28,11 +31,9 @@ def deploy():
|
||||
if not default_dir.is_dir():
|
||||
raise NotADirectoryError(f'{default_dir} is not a directory')
|
||||
|
||||
# migrate database to latest revision
|
||||
print('Migrate database to latest revision')
|
||||
upgrade()
|
||||
|
||||
# Insert/Update default database values
|
||||
print('Insert/Update default Roles')
|
||||
Role.insert_defaults()
|
||||
print('Insert/Update default Users')
|
||||
@ -44,4 +45,9 @@ def deploy():
|
||||
print('Insert/Update default TesseractOCRPipelineModels')
|
||||
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
|
||||
|
23
wsgi.py
23
wsgi.py
@ -8,20 +8,6 @@ from flask import Flask # noqa
|
||||
from typing import Any, Dict # noqa
|
||||
from app import create_app, db, scheduler, socketio # 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()
|
||||
@ -48,12 +34,9 @@ def make_shell_context() -> Dict[str, Any]:
|
||||
|
||||
|
||||
def main():
|
||||
with app.app_context():
|
||||
if app.config['NOPAQUE_IS_PRIMARY_INSTANCE']:
|
||||
for corpus in models.Corpus.query.filter(models.Corpus.num_analysis_sessions > 0).all():
|
||||
corpus.num_analysis_sessions = 0
|
||||
db.session.commit()
|
||||
scheduler.start()
|
||||
if app.config['NOPAQUE_IS_PRIMARY_INSTANCE']:
|
||||
with app.app_context():
|
||||
scheduler.start()
|
||||
socketio.run(app, host='0.0.0.0')
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user