Add job delete function.

This commit is contained in:
Stephan Porada 2019-09-12 16:45:05 +02:00
parent 2991082f1f
commit b2e2484725
3 changed files with 24 additions and 3 deletions

View File

@ -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'))

View File

@ -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):

View File

@ -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: