nopaque/web/app/results/tasks.py

18 lines
532 B
Python

from ..decorators import background
from ..models import Result
import os
import shutil
@background
def delete_result(result_id, *args, **kwargs):
app = kwargs['app']
with app.app_context():
result = Result.query.get(result_id)
if result is None:
return
result_file_path = os.path.join(app.config['NOPAQUE_STORAGE'],
result.file[0].dir)
shutil.rmtree(result_file_path)
result.delete() # cascades down and also deletes ResultFile