Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
nopaque
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Admin message
Looking for advice? Join the
Matrix channel for GitLab users in Bielefeld
!
Show more breadcrumbs
SFB 1288 - INF
nopaque
Commits
3a989534
Commit
3a989534
authored
5 years ago
by
Patrick Jentsch
Browse files
Options
Downloads
Patches
Plain Diff
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
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
app/corpora/tasks.py
+6
-3
6 additions, 3 deletions
app/corpora/tasks.py
app/decorators.py
+2
-2
2 additions, 2 deletions
app/decorators.py
app/jobs/tasks.py
+2
-1
2 additions, 1 deletion
app/jobs/tasks.py
app/profile/tasks.py
+2
-4
2 additions, 4 deletions
app/profile/tasks.py
with
12 additions
and
10 deletions
app/corpora/tasks.py
+
6
−
3
View file @
3a989534
...
...
@@ -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
:
...
...
This diff is collapsed.
Click to expand it.
app/decorators.py
+
2
−
2
View file @
3a989534
...
...
@@ -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
...
...
This diff is collapsed.
Click to expand it.
app/jobs/tasks.py
+
2
−
1
View file @
3a989534
...
...
@@ -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
:
...
...
This diff is collapsed.
Click to expand it.
app/profile/tasks.py
+
2
−
4
View file @
3a989534
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
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment