Rename TaskRunner to Daemon (because it essentially is one) and restructure cli

This commit is contained in:
Patrick Jentsch 2021-09-22 13:53:39 +02:00
parent e0219e84c9
commit 17cbfd71b4
7 changed files with 46 additions and 27 deletions

View File

@ -11,15 +11,26 @@ def register(app):
# create or update user roles
Role.insert_roles()
@app.cli.command()
def tasks():
from app.tasks import TaskRunner
task_runner = TaskRunner()
task_runner.run()
@app.cli.group()
def daemon():
"""Daemon commands."""
pass
@app.cli.command()
@daemon.command()
def run():
"""Run daemon"""
from app.daemon import Daemon
daemon = Daemon()
daemon.run()
@app.cli.group()
def test():
"""Run the unit tests."""
"""Test commands."""
pass
@test.command()
def run():
"""Run unit tests."""
import unittest
tests = unittest.TestLoader().discover('tests')
unittest.TextTestRunner(verbosity=2).run(tests)

20
app/daemon/__init__.py Normal file
View File

@ -0,0 +1,20 @@
from app import db
from time import sleep
from .corpus_utils import CheckCorporaMixin
from .job_utils import CheckJobsMixin
import docker
class Daemon(CheckCorporaMixin, CheckJobsMixin):
def __init__(self):
self.docker = docker.from_env()
def run(self):
while True:
try:
self.check_corpora()
self.check_jobs()
db.session.commit()
except:
pass
sleep(1.5)

View File

@ -1,14 +0,0 @@
from .corpus_utils import CheckCorporaMixin
from .job_utils import CheckJobsMixin
from ..import db, socketio
import docker
class TaskRunner(CheckCorporaMixin, CheckJobsMixin):
def __init__(self):
self.docker = docker.from_env()
def run(self):
self.check_corpora()
self.check_jobs()
db.session.commit()

12
boot.sh
View File

@ -1,19 +1,19 @@
#!/bin/bash
source venv/bin/activate
if [[ "${NOPAQUE_DAEMON_ENABLED:-True}" == "True" ]]; then
echo "INFO Starting nopaque daemon process..."
./nopaque-daemon.sh &
fi
if [[ "${#}" -eq 0 ]]; then
while true; do
echo "INFO Run deployment tasks..."
flask deploy
if [[ "${?}" == "0" ]]; then
break
fi
echo "Deploy command failed, retrying in 5 secs..."
echo "WARNING ...Failed, retrying in 5 secs..."
sleep 5
done
if [[ "${NOPAQUE_DAEMON_ENABLED:-True}" == "True" ]]; then
echo "INFO Start nopaque daemon..."
flask daemon run &
fi
gunicorn \
--access-logfile - \
--error-logfile - \

View File

@ -46,6 +46,8 @@ class Config:
''' # nopaque # '''
NOPAQUE_ADMIN = os.environ.get('NOPAQUE_ADMIN')
NOPAQUE_CONTACT = os.environ.get('NOPAQUE_CONTACT')
NOPAQUE_DAEMON_ENABLED = \
os.environ.get('NOPAQUE_DAEMON_ENABLED', 'true').lower() == 'true'
NOPAQUE_DATA_DIR = os.environ.get('NOPAQUE_DATA_DIR', '/mnt/nopaque')
NOPAQUE_MAIL_SUBJECT_PREFIX = '[nopaque]'
NOPAQUE_SOCKETIO_MESSAGE_QUEUE_URI = \