2021-09-22 11:53:39 +00:00
|
|
|
from app import db
|
2021-11-16 14:23:57 +00:00
|
|
|
from flask import current_app
|
2021-09-22 11:53:39 +00:00
|
|
|
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()
|
2021-11-16 14:23:57 +00:00
|
|
|
self.docker.login(
|
|
|
|
username=current_app.config['NOPAQUE_DOCKER_REGISTRY_USERNAME'],
|
|
|
|
password=current_app.config['NOPAQUE_DOCKER_REGISTRY_PASSWORD'],
|
|
|
|
registry=current_app.config['NOPAQUE_DOCKER_REGISTRY']
|
|
|
|
)
|
2021-09-22 11:53:39 +00:00
|
|
|
|
|
|
|
def run(self):
|
|
|
|
while True:
|
|
|
|
try:
|
|
|
|
self.check_corpora()
|
|
|
|
self.check_jobs()
|
|
|
|
db.session.commit()
|
2021-11-30 15:22:16 +00:00
|
|
|
except Exception as e:
|
|
|
|
current_app.logger.warning(e)
|
2021-09-22 11:53:39 +00:00
|
|
|
pass
|
|
|
|
sleep(1.5)
|