from .. import db
from ..decorators import background
from ..models import Result


@background
def delete_result(result_id, *args, **kwargs):
    with kwargs['app'].app_context():
        result = Result.query.get(result_id)
        if result is None:
            raise Exception('Result {} not found'.format(result_id))
        result.delete()  # cascades down and also deletes ResultFile
        db.session.commit()