mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-11-15 01:05:42 +00:00
29 lines
895 B
Python
29 lines
895 B
Python
from time import sleep
|
|
from .. import db
|
|
from ..decorators import background
|
|
from ..models import Job
|
|
import os
|
|
import shutil
|
|
|
|
|
|
@background
|
|
def delete_job(app, job_id):
|
|
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)
|
|
job.delete()
|