diff --git a/app/main/views.py b/app/main/views.py index e48c5dce..4b6aac74 100644 --- a/app/main/views.py +++ b/app/main/views.py @@ -7,6 +7,7 @@ from .. import db from ..models import Corpus, Job import os import logging +import time @main.route('/') @@ -144,7 +145,17 @@ def job_download(job_id): @login_required def delete_job(job_id): logger = logging.getLogger(__name__) + logger.warning(job_id) job = Job.query.filter_by(id=job_id).first() + logger.warning('Job status: {}'.format(job.status)) job.flag_for_stop() logger.warning('Job status: {}'.format(job.status)) + deleted = False + while deleted is False: + db.session.refresh(job) + if job.status == 'deleted': + logger.warning('Job status is deleted.') + time.sleep(5) + job.delete_job() + deleted = True return redirect(url_for('main.dashboard')) diff --git a/app/models.py b/app/models.py index a59a6a95..4474bf03 100644 --- a/app/models.py +++ b/app/models.py @@ -5,6 +5,9 @@ from werkzeug.security import generate_password_hash, check_password_hash from . import db from . import login_manager from datetime import datetime +import os +import shutil +import logging class Permission: @@ -293,13 +296,19 @@ class Job(db.Model): self.status = 'stopping' db.session.commit() - def delete_job(self, job_id): + def delete_job(self): """ Delete job with given job id from database. Also delete associated job files """ - # TODO - pass + logger = logging.getLogger(__name__) + delete_path = os.path.join('/mnt/opaque/', str(self.user_id), 'jobs', + str(self.id)) + logger.warning('Delete path is: {}'.format(delete_path)) + if os.path.exists(delete_path): + shutil.rmtree(delete_path) + db.session.delete(self) + db.session.commit() class Corpus(db.Model): diff --git a/docker-compose.yml b/docker-compose.yml index 47e97091..6ac0fa11 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -36,6 +36,7 @@ services: volumes: - ./logs:/home/opaque_daemon/logs - $HOME/.docker/config.json:/home/opaque_daemon/.docker/config.json + - /home/stephan/Repos/own/opaque_daemon/opaque_daemon.py:/home/opaque_daemon/opaque_daemon.py db: deploy: placement: