mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2025-06-14 10:00:40 +00:00
Move file deletion to model methods. add restart job button.
This commit is contained in:
@ -1,9 +1,5 @@
|
||||
from time import sleep
|
||||
from .. import db, logger
|
||||
from ..decorators import background
|
||||
from ..models import Job
|
||||
import os
|
||||
import shutil
|
||||
|
||||
|
||||
@background
|
||||
@ -12,20 +8,7 @@ def delete_job(job_id, *args, **kwargs):
|
||||
with app.app_context():
|
||||
job = Job.query.get(job_id)
|
||||
if job is None:
|
||||
return
|
||||
if job.status not in ['complete', 'failed']:
|
||||
job.status = 'canceling'
|
||||
db.session.commit()
|
||||
while job.status != 'canceled':
|
||||
# In case the daemon handled a job in any way
|
||||
if job.status != 'canceling':
|
||||
job.status = 'canceling'
|
||||
db.session.commit()
|
||||
sleep(1)
|
||||
db.session.refresh(job)
|
||||
path = os.path.join(app.config['NOPAQUE_STORAGE'], str(job.user_id),
|
||||
'jobs', str(job.id))
|
||||
shutil.rmtree(path, ignore_errors=True)
|
||||
raise Exception('Could not find job with id {}'.format(job_id))
|
||||
job.delete()
|
||||
|
||||
|
||||
@ -35,16 +18,5 @@ def restart_job(job_id, *args, **kwargs):
|
||||
with app.app_context():
|
||||
job = Job.query.get(job_id)
|
||||
if job is None:
|
||||
logger.warning('Job not found')
|
||||
return
|
||||
if job.status != 'failed':
|
||||
logger.warning('Job not failed')
|
||||
return
|
||||
logger.warning('Restarted')
|
||||
job_dir = os.path.join(app.config['NOPAQUE_STORAGE'],
|
||||
str(job.user_id),
|
||||
'jobs',
|
||||
str(job.id))
|
||||
shutil.rmtree(os.path.join(job_dir, 'output'), ignore_errors=True)
|
||||
shutil.rmtree(os.path.join(job_dir, 'pyflow.data'), ignore_errors=True)
|
||||
raise Exception('Could not find job with id {}'.format(job_id))
|
||||
job.restart()
|
||||
|
@ -56,7 +56,7 @@ def download_job_input(job_id, job_input_id):
|
||||
def restart(job_id):
|
||||
job = Job.query.get_or_404(job_id)
|
||||
if job.status != 'failed':
|
||||
flash('Job can not be restarted!', 'job')
|
||||
flash('Could not restart job: status is not "failed"', 'error')
|
||||
else:
|
||||
tasks.restart_job(job_id)
|
||||
flash('Job has been restarted!', 'job')
|
||||
|
Reference in New Issue
Block a user