mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-11-15 01:05:42 +00:00
Make the app arg in @background functions a bit less magical
This commit is contained in:
parent
83c05d93b0
commit
3a989534cf
@ -7,7 +7,8 @@ import shutil
|
|||||||
|
|
||||||
|
|
||||||
@background
|
@background
|
||||||
def build_corpus(app, corpus_id):
|
def build_corpus(corpus_id, *args, **kwargs):
|
||||||
|
app = kwargs['app']
|
||||||
with app.app_context():
|
with app.app_context():
|
||||||
corpus = Corpus.query.get(corpus_id)
|
corpus = Corpus.query.get(corpus_id)
|
||||||
if corpus is None:
|
if corpus is None:
|
||||||
@ -48,7 +49,8 @@ def build_corpus(app, corpus_id):
|
|||||||
|
|
||||||
|
|
||||||
@background
|
@background
|
||||||
def delete_corpus(app, corpus_id):
|
def delete_corpus(corpus_id, *args, **kwargs):
|
||||||
|
app = kwargs['app']
|
||||||
with app.app_context():
|
with app.app_context():
|
||||||
corpus = Corpus.query.get(corpus_id)
|
corpus = Corpus.query.get(corpus_id)
|
||||||
if corpus is None:
|
if corpus is None:
|
||||||
@ -60,7 +62,8 @@ def delete_corpus(app, corpus_id):
|
|||||||
|
|
||||||
|
|
||||||
@background
|
@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():
|
with app.app_context():
|
||||||
corpus_file = CorpusFile.query.get(corpus_file_id)
|
corpus_file = CorpusFile.query.get(corpus_file_id)
|
||||||
if corpus_file is None:
|
if corpus_file is None:
|
||||||
|
@ -19,8 +19,8 @@ def background(f):
|
|||||||
''' This decorator executes a function in a Thread '''
|
''' This decorator executes a function in a Thread '''
|
||||||
@wraps(f)
|
@wraps(f)
|
||||||
def wrapped(*args, **kwargs):
|
def wrapped(*args, **kwargs):
|
||||||
app = current_app._get_current_object()
|
kwargs['app'] = current_app._get_current_object()
|
||||||
thread = Thread(target=f, args=(app, *args), kwargs=kwargs)
|
thread = Thread(target=f, args=args, kwargs=kwargs)
|
||||||
thread.start()
|
thread.start()
|
||||||
return thread
|
return thread
|
||||||
return wrapped
|
return wrapped
|
||||||
|
@ -7,7 +7,8 @@ import shutil
|
|||||||
|
|
||||||
|
|
||||||
@background
|
@background
|
||||||
def delete_job(app, job_id):
|
def delete_job(job_id, *args, **kwargs):
|
||||||
|
app = kwargs['app']
|
||||||
with app.app_context():
|
with app.app_context():
|
||||||
job = Job.query.get(job_id)
|
job = Job.query.get(job_id)
|
||||||
if job is None:
|
if job is None:
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
from .. import logger
|
|
||||||
from ..decorators import background
|
from ..decorators import background
|
||||||
from ..models import User
|
from ..models import User
|
||||||
import os
|
import os
|
||||||
@ -6,13 +5,12 @@ import shutil
|
|||||||
|
|
||||||
|
|
||||||
@background
|
@background
|
||||||
def delete_user(app, user_id):
|
def delete_user(user_id, *args, **kwargs):
|
||||||
logger.warning('aufgerufen')
|
app = kwargs['app']
|
||||||
with app.app_context():
|
with app.app_context():
|
||||||
user = User.query.get(user_id)
|
user = User.query.get(user_id)
|
||||||
if user is None:
|
if user is None:
|
||||||
raise Exception('User {} not found!'.format(user_id))
|
raise Exception('User {} not found!'.format(user_id))
|
||||||
logger.warning('deleting user')
|
|
||||||
path = os.path.join(app.config['NOPAQUE_STORAGE'], str(user.id))
|
path = os.path.join(app.config['NOPAQUE_STORAGE'], str(user.id))
|
||||||
shutil.rmtree(path, ignore_errors=True)
|
shutil.rmtree(path, ignore_errors=True)
|
||||||
user.delete()
|
user.delete()
|
||||||
|
Loading…
Reference in New Issue
Block a user