Skip to content
Snippets Groups Projects
Commit 3a989534 authored by Patrick Jentsch's avatar Patrick Jentsch
Browse files

Make the app arg in @background functions a bit less magical

parent 83c05d93
No related branches found
No related tags found
No related merge requests found
......@@ -7,7 +7,8 @@ import shutil
@background
def build_corpus(app, corpus_id):
def build_corpus(corpus_id, *args, **kwargs):
app = kwargs['app']
with app.app_context():
corpus = Corpus.query.get(corpus_id)
if corpus is None:
......@@ -48,7 +49,8 @@ def build_corpus(app, corpus_id):
@background
def delete_corpus(app, corpus_id):
def delete_corpus(corpus_id, *args, **kwargs):
app = kwargs['app']
with app.app_context():
corpus = Corpus.query.get(corpus_id)
if corpus is None:
......@@ -60,7 +62,8 @@ def delete_corpus(app, corpus_id):
@background
def delete_corpus_file(app, corpus_file_id):
def delete_corpus_file(corpus_file_id, *args, **kwargs):
app = kwargs['app']
with app.app_context():
corpus_file = CorpusFile.query.get(corpus_file_id)
if corpus_file is None:
......
......@@ -19,8 +19,8 @@ def background(f):
''' This decorator executes a function in a Thread '''
@wraps(f)
def wrapped(*args, **kwargs):
app = current_app._get_current_object()
thread = Thread(target=f, args=(app, *args), kwargs=kwargs)
kwargs['app'] = current_app._get_current_object()
thread = Thread(target=f, args=args, kwargs=kwargs)
thread.start()
return thread
return wrapped
......
......@@ -7,7 +7,8 @@ import shutil
@background
def delete_job(app, job_id):
def delete_job(job_id, *args, **kwargs):
app = kwargs['app']
with app.app_context():
job = Job.query.get(job_id)
if job is None:
......
from .. import logger
from ..decorators import background
from ..models import User
import os
......@@ -6,13 +5,12 @@ import shutil
@background
def delete_user(app, user_id):
logger.warning('aufgerufen')
def delete_user(user_id, *args, **kwargs):
app = kwargs['app']
with app.app_context():
user = User.query.get(user_id)
if user is None:
raise Exception('User {} not found!'.format(user_id))
logger.warning('deleting user')
path = os.path.join(app.config['NOPAQUE_STORAGE'], str(user.id))
shutil.rmtree(path, ignore_errors=True)
user.delete()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment