Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
AlekSIS-Core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Contributor analytics
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
Show more breadcrumbs
AlekSIS®
Official
AlekSIS-Core
Commits
c81581cc
Verified
Commit
c81581cc
authored
4 years ago
by
Nik | Klampfradler
Browse files
Options
Downloads
Patches
Plain Diff
Simplify and rename task recording decorator
parent
0bdf5664
No related branches found
Branches containing commit
No related tags found
Tags containing commit
2 merge requests
!494
Refactor ProgressRecorder for non-optional Celery usage and add doc strings
,
!491
Resolve "Make Celery non-optional"
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
aleksis/core/util/celery_progress.py
+10
-21
10 additions, 21 deletions
aleksis/core/util/celery_progress.py
with
10 additions
and
21 deletions
aleksis/core/util/celery_progress.py
+
10
−
21
View file @
c81581cc
import
time
from
decimal
import
Decimal
from
functools
import
wraps
from
typing
import
Callable
,
Union
from
celery_progress.backend
import
PROGRESS_STATE
,
AbstractProgressRecorder
...
...
@@ -99,26 +99,15 @@ class ProgressRecorder(AbstractProgressRecorder):
self
.
set_progress
(
self
.
current
)
@classmethod
def
record
(
cls
,
orig
:
Callable
):
"""
Decorate a function to use Celery and a progress recorder.
It wraps the function in a Celery task and calls its delay method when invoked.
Additionally, it adds the matching `ProgressRecorder` instance as first argument.
def
recorded_task
(
cls
,
orig
:
Callable
)
->
app
.
Task
:
"""
Create a Celery task that receives a ProgressRecorder.
Returns a Task object with a wrapper that passes the recorder instance
as the recorder keyword argument.
"""
@wraps
(
orig
)
def
_inject_recorder
(
task
,
*
args
,
**
kwargs
):
recorder
=
ProgressRecorder
(
task
)
return
orig
(
*
args
,
**
kwargs
,
recorder
=
recorder
)
def
recorder_func
(
self
,
*
args
,
**
kwargs
):
recorder
=
ProgressRecorder
(
self
)
orig
(
recorder
,
*
args
,
**
kwargs
)
var_name
=
f
"
{
orig
.
__module__
}
.
{
orig
.
__name__
}
"
task
=
app
.
task
(
recorder_func
,
bind
=
True
,
name
=
var_name
)
def
wrapped
(
*
args
,
**
kwargs
):
return
task
.
delay
(
*
args
,
**
kwargs
)
return
wrapped
return
app
.
task
(
_inject_recorder
,
bind
=
True
)
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