Skip to content
Snippets Groups Projects
Verified Commit 9e8b9077 authored by Nik | Klampfradler's avatar Nik | Klampfradler
Browse files

Fix generation of record_task decorator with arguments

parent 54df673c
No related branches found
No related tags found
1 merge request!491Resolve "Make Celery non-optional"
Pipeline #5916 passed
......@@ -140,18 +140,24 @@ class ProgressRecorder(AbstractProgressRecorder):
self.set_progress(description=message, level=level)
def recorded_task(orig: Callable, *args, **kwargs) -> app.Task:
def recorded_task(*args, **kwargs) -> Union[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 _real_decorator(orig: Callable) -> app.Task:
@wraps(orig)
def _inject_recorder(task, *args, **kwargs):
recorder = ProgressRecorder(task)
return orig(*args, **kwargs, recorder=recorder)
# Force bind to True because _inject_recorder needs the Task object
kwargs["bind"] = True
return app.task(_inject_recorder, *args, **kwargs)
# Force bind to True because _inject_recorder needs the Task object
kwargs["bind"] = True
return app.task(_inject_recorder, *args, **kwargs)
if len(args) == 1 and isinstance(args[0], Callable) and not kwargs:
return _real_decorator(args[0])
else:
return _real_decorator
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment