mirror of
				https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
				synced 2025-11-04 04:12:45 +00:00 
			
		
		
		
	Rename TaskRunner to Daemon (because it essentially is one) and restructure cli
This commit is contained in:
		
							
								
								
									
										25
									
								
								app/cli.py
									
									
									
									
									
								
							
							
						
						
									
										25
									
								
								app/cli.py
									
									
									
									
									
								
							@@ -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
									
								
							
							
						
						
									
										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
 | 
			
		||||
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 - \
 | 
			
		||||
 
 | 
			
		||||
@@ -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 = \
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user