2021-11-16 15:23:57 +01:00
|
|
|
from . import db
|
|
|
|
from .models import Corpus, Role
|
2021-09-15 12:31:53 +02:00
|
|
|
from flask_migrate import upgrade
|
|
|
|
|
|
|
|
|
|
|
|
def register(app):
|
|
|
|
@app.cli.command()
|
|
|
|
def deploy():
|
2021-12-07 14:18:05 +01:00
|
|
|
''' Run deployment tasks. '''
|
2021-09-15 12:31:53 +02:00
|
|
|
# migrate database to latest revision
|
|
|
|
upgrade()
|
|
|
|
# create or update user roles
|
|
|
|
Role.insert_roles()
|
|
|
|
|
2021-09-22 13:53:39 +02:00
|
|
|
@app.cli.group()
|
|
|
|
def daemon():
|
2021-12-07 14:18:05 +01:00
|
|
|
''' Daemon commands. '''
|
2021-09-22 13:53:39 +02:00
|
|
|
pass
|
2021-09-15 12:31:53 +02:00
|
|
|
|
2021-09-22 14:13:59 +02:00
|
|
|
@daemon.command('run')
|
2021-09-22 13:58:46 +02:00
|
|
|
def run_daemon():
|
2021-12-07 14:18:05 +01:00
|
|
|
''' Run daemon '''
|
|
|
|
corpus: Corpus
|
2021-11-16 15:23:57 +01:00
|
|
|
for corpus in Corpus.query.filter(Corpus.num_analysis_sessions > 0):
|
|
|
|
corpus.num_analysis_sessions = 0
|
|
|
|
db.session.commit()
|
2021-09-22 13:53:39 +02:00
|
|
|
from app.daemon import Daemon
|
2021-12-07 14:18:05 +01:00
|
|
|
daemon: Daemon = Daemon()
|
2021-09-22 13:53:39 +02:00
|
|
|
daemon.run()
|
|
|
|
|
|
|
|
@app.cli.group()
|
2021-09-15 12:31:53 +02:00
|
|
|
def test():
|
2021-12-07 14:18:05 +01:00
|
|
|
''' Test commands. '''
|
2021-09-22 13:53:39 +02:00
|
|
|
pass
|
|
|
|
|
2021-09-22 14:13:59 +02:00
|
|
|
@test.command('run')
|
2021-09-22 13:58:46 +02:00
|
|
|
def run_test():
|
2021-12-07 14:18:05 +01:00
|
|
|
''' Run unit tests. '''
|
|
|
|
from unittest import TestLoader, TextTestRunner
|
|
|
|
from unittest.suite import TestSuite
|
|
|
|
tests: TestSuite = TestLoader().discover('tests')
|
|
|
|
TextTestRunner(verbosity=2).run(tests)
|