mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-11-15 01:05:42 +00:00
Rename TaskRunner to Daemon (because it essentially is one) and restructure cli
This commit is contained in:
parent
e0219e84c9
commit
17cbfd71b4
25
app/cli.py
25
app/cli.py
@ -11,15 +11,26 @@ def register(app):
|
|||||||
# create or update user roles
|
# create or update user roles
|
||||||
Role.insert_roles()
|
Role.insert_roles()
|
||||||
|
|
||||||
@app.cli.command()
|
@app.cli.group()
|
||||||
def tasks():
|
def daemon():
|
||||||
from app.tasks import TaskRunner
|
"""Daemon commands."""
|
||||||
task_runner = TaskRunner()
|
pass
|
||||||
task_runner.run()
|
|
||||||
|
|
||||||
@app.cli.command()
|
@daemon.command()
|
||||||
|
def run():
|
||||||
|
"""Run daemon"""
|
||||||
|
from app.daemon import Daemon
|
||||||
|
daemon = Daemon()
|
||||||
|
daemon.run()
|
||||||
|
|
||||||
|
@app.cli.group()
|
||||||
def test():
|
def test():
|
||||||
"""Run the unit tests."""
|
"""Test commands."""
|
||||||
|
pass
|
||||||
|
|
||||||
|
@test.command()
|
||||||
|
def run():
|
||||||
|
"""Run unit tests."""
|
||||||
import unittest
|
import unittest
|
||||||
tests = unittest.TestLoader().discover('tests')
|
tests = unittest.TestLoader().discover('tests')
|
||||||
unittest.TextTestRunner(verbosity=2).run(tests)
|
unittest.TextTestRunner(verbosity=2).run(tests)
|
||||||
|
20
app/daemon/__init__.py
Normal file
20
app/daemon/__init__.py
Normal 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)
|
@ -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
12
boot.sh
@ -1,19 +1,19 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
source venv/bin/activate
|
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
|
if [[ "${#}" -eq 0 ]]; then
|
||||||
while true; do
|
while true; do
|
||||||
|
echo "INFO Run deployment tasks..."
|
||||||
flask deploy
|
flask deploy
|
||||||
if [[ "${?}" == "0" ]]; then
|
if [[ "${?}" == "0" ]]; then
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
echo "Deploy command failed, retrying in 5 secs..."
|
echo "WARNING ...Failed, retrying in 5 secs..."
|
||||||
sleep 5
|
sleep 5
|
||||||
done
|
done
|
||||||
|
if [[ "${NOPAQUE_DAEMON_ENABLED:-True}" == "True" ]]; then
|
||||||
|
echo "INFO Start nopaque daemon..."
|
||||||
|
flask daemon run &
|
||||||
|
fi
|
||||||
gunicorn \
|
gunicorn \
|
||||||
--access-logfile - \
|
--access-logfile - \
|
||||||
--error-logfile - \
|
--error-logfile - \
|
||||||
|
@ -46,6 +46,8 @@ class Config:
|
|||||||
''' # nopaque # '''
|
''' # nopaque # '''
|
||||||
NOPAQUE_ADMIN = os.environ.get('NOPAQUE_ADMIN')
|
NOPAQUE_ADMIN = os.environ.get('NOPAQUE_ADMIN')
|
||||||
NOPAQUE_CONTACT = os.environ.get('NOPAQUE_CONTACT')
|
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_DATA_DIR = os.environ.get('NOPAQUE_DATA_DIR', '/mnt/nopaque')
|
||||||
NOPAQUE_MAIL_SUBJECT_PREFIX = '[nopaque]'
|
NOPAQUE_MAIL_SUBJECT_PREFIX = '[nopaque]'
|
||||||
NOPAQUE_SOCKETIO_MESSAGE_QUEUE_URI = \
|
NOPAQUE_SOCKETIO_MESSAGE_QUEUE_URI = \
|
||||||
|
Loading…
Reference in New Issue
Block a user