p1-taskqueue 0.1.6__py3-none-any.whl → 0.1.8__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of p1-taskqueue might be problematic. Click here for more details.
- {p1_taskqueue-0.1.6.dist-info → p1_taskqueue-0.1.8.dist-info}/METADATA +1 -1
- p1_taskqueue-0.1.8.dist-info/RECORD +9 -0
- taskqueue/__init__.py +2 -1
- taskqueue/cmanager.py +45 -8
- taskqueue/libs/helper_test.py +9 -4
- p1_taskqueue-0.1.6.dist-info/RECORD +0 -9
- {p1_taskqueue-0.1.6.dist-info → p1_taskqueue-0.1.8.dist-info}/WHEEL +0 -0
- {p1_taskqueue-0.1.6.dist-info → p1_taskqueue-0.1.8.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
taskqueue/__init__.py,sha256=nNHXIyysNLom9f8of-d__pWJ-YF53Mbrbsb1frPzPPI,298
|
|
2
|
+
taskqueue/celery_app.py,sha256=dUT-7XzsSQbr8vKrLv7f_6iYxTCUEJZHEt9fL-KIQ5U,3302
|
|
3
|
+
taskqueue/cmanager.py,sha256=raQwdccYTpWRiW8UGU5OcUEN0jZr9TTlIEnhZGtamiI,12274
|
|
4
|
+
taskqueue/libs/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
+
taskqueue/libs/helper_test.py,sha256=aZSeW5BK6j3NH7OaD8hRIPI7yaZi9hEvlJy6H_u6g5I,3991
|
|
6
|
+
p1_taskqueue-0.1.8.dist-info/METADATA,sha256=-RuB08xZgH4fsf10073v3nbkj4gNwB3e6-gRB_rtNjc,1508
|
|
7
|
+
p1_taskqueue-0.1.8.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
8
|
+
p1_taskqueue-0.1.8.dist-info/top_level.txt,sha256=hA3SM1ik2K8iPqtlt_-_nJ4TAePwHPN3vsOc4EiynqU,10
|
|
9
|
+
p1_taskqueue-0.1.8.dist-info/RECORD,,
|
taskqueue/__init__.py
CHANGED
taskqueue/cmanager.py
CHANGED
|
@@ -28,6 +28,26 @@ def _is_class_method(func: Any) -> bool:
|
|
|
28
28
|
)
|
|
29
29
|
|
|
30
30
|
|
|
31
|
+
def taskqueue_class(cls):
|
|
32
|
+
"""Decorator to automatically capture init arguments for taskqueue."""
|
|
33
|
+
original_init = cls.__init__
|
|
34
|
+
|
|
35
|
+
def wrapped_init(self, *args, **kwargs):
|
|
36
|
+
self._taskqueue_init_args = list(args)
|
|
37
|
+
self._taskqueue_init_kwargs = dict(kwargs)
|
|
38
|
+
original_init(self, *args, **kwargs)
|
|
39
|
+
|
|
40
|
+
cls.__init__ = wrapped_init
|
|
41
|
+
return cls
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def _extract_init_args_from_instance(instance: Any) -> Tuple[list, dict]:
|
|
45
|
+
"""Extract init arguments from instance."""
|
|
46
|
+
init_args = getattr(instance, '_taskqueue_init_args', [])
|
|
47
|
+
init_kwargs = getattr(instance, '_taskqueue_init_kwargs', {})
|
|
48
|
+
return init_args, init_kwargs
|
|
49
|
+
|
|
50
|
+
|
|
31
51
|
def _split_function_and_queue_kwargs(kwargs: Dict[str, Any]) -> Tuple[Dict[str, Any], Dict[str, Any]]:
|
|
32
52
|
# To prevent confusion whether a kwargs is for function or queue kwargs(i.e celery options and on_commit),
|
|
33
53
|
# ignore confusing kwargs while give warning
|
|
@@ -62,10 +82,20 @@ def _build_dynamic_task_call(func: Any, *args: Any, **func_kwargs: Any) -> Tuple
|
|
|
62
82
|
module_path = klass.__module__
|
|
63
83
|
class_name = klass.__name__
|
|
64
84
|
method_name = func.__name__
|
|
85
|
+
|
|
86
|
+
init_args, init_kwargs = _extract_init_args_from_instance(instance)
|
|
87
|
+
|
|
65
88
|
task_name = "taskqueue.cmanager.dynamic_class_method_executor"
|
|
66
|
-
task_args = [
|
|
67
|
-
|
|
68
|
-
|
|
89
|
+
task_args = []
|
|
90
|
+
task_kwargs: Dict[str, Any] = {
|
|
91
|
+
"module_path": module_path,
|
|
92
|
+
"class_name": class_name,
|
|
93
|
+
"method_name": method_name,
|
|
94
|
+
"args": list(args),
|
|
95
|
+
"kwargs": dict(func_kwargs),
|
|
96
|
+
"init_args": init_args,
|
|
97
|
+
"init_kwargs": init_kwargs,
|
|
98
|
+
}
|
|
69
99
|
return task_name, task_args, task_kwargs
|
|
70
100
|
|
|
71
101
|
module_path = getattr(func, "__module__", None)
|
|
@@ -75,8 +105,13 @@ def _build_dynamic_task_call(func: Any, *args: Any, **func_kwargs: Any) -> Tuple
|
|
|
75
105
|
"Unsupported callable type for Celery enqueue. Provide a module-level function or a class method.")
|
|
76
106
|
|
|
77
107
|
task_name = "taskqueue.cmanager.dynamic_function_executor"
|
|
78
|
-
task_args = [
|
|
79
|
-
task_kwargs = {
|
|
108
|
+
task_args = []
|
|
109
|
+
task_kwargs = {
|
|
110
|
+
"module_path": module_path,
|
|
111
|
+
"function_name": function_name,
|
|
112
|
+
"args": list(args),
|
|
113
|
+
"kwargs": dict(func_kwargs),
|
|
114
|
+
}
|
|
80
115
|
return task_name, task_args, task_kwargs
|
|
81
116
|
|
|
82
117
|
|
|
@@ -205,7 +240,7 @@ cm = CManager()
|
|
|
205
240
|
|
|
206
241
|
# Dynamic task executors - handle function and class method execution
|
|
207
242
|
@shared_task(bind=True, max_retries=K_MAX_RETRY_COUNT)
|
|
208
|
-
def dynamic_function_executor(self, module_path, function_name, args=None, kwargs=None, retry=None):
|
|
243
|
+
def dynamic_function_executor(self, module_path=None, function_name=None, args=None, kwargs=None, retry=None):
|
|
209
244
|
job_id = self.request.id
|
|
210
245
|
try:
|
|
211
246
|
module = importlib.import_module(module_path)
|
|
@@ -237,12 +272,14 @@ def dynamic_function_executor(self, module_path, function_name, args=None, kwarg
|
|
|
237
272
|
|
|
238
273
|
|
|
239
274
|
@shared_task(bind=True, max_retries=K_MAX_RETRY_COUNT)
|
|
240
|
-
def dynamic_class_method_executor(self, module_path, class_name, method_name, args=None, kwargs=None, retry=None):
|
|
275
|
+
def dynamic_class_method_executor(self, module_path=None, class_name=None, method_name=None, args=None, kwargs=None, init_args=None, init_kwargs=None, retry=None):
|
|
241
276
|
job_id = self.request.id
|
|
242
277
|
try:
|
|
243
278
|
module = importlib.import_module(module_path)
|
|
244
279
|
class_obj = getattr(module, class_name)
|
|
245
|
-
|
|
280
|
+
init_args = init_args or []
|
|
281
|
+
init_kwargs = init_kwargs or {}
|
|
282
|
+
instance = class_obj(*init_args, **init_kwargs)
|
|
246
283
|
method = getattr(instance, method_name)
|
|
247
284
|
args = args or []
|
|
248
285
|
kwargs = kwargs or {}
|
taskqueue/libs/helper_test.py
CHANGED
|
@@ -58,10 +58,15 @@ def celery_worker_burst(include_func_names: List[str], channel: str = "default")
|
|
|
58
58
|
decoded_body) > 1 else {}
|
|
59
59
|
|
|
60
60
|
full_func_name = ""
|
|
61
|
-
if task_name.endswith("dynamic_function_executor")
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
full_func_name = f"{
|
|
61
|
+
if task_name.endswith("dynamic_function_executor"):
|
|
62
|
+
module_path = task_kwargs.get('module_path', '')
|
|
63
|
+
function_name = task_kwargs.get('function_name', '')
|
|
64
|
+
full_func_name = f"{module_path}.{function_name}"
|
|
65
|
+
elif task_name.endswith("dynamic_class_method_executor"):
|
|
66
|
+
module_path = task_kwargs.get('module_path', '')
|
|
67
|
+
class_name = task_kwargs.get('class_name', '')
|
|
68
|
+
method_name = task_kwargs.get('method_name', '')
|
|
69
|
+
full_func_name = f"{module_path}.{class_name}.{method_name}"
|
|
65
70
|
|
|
66
71
|
should_execute = full_func_name in included_set if full_func_name else False
|
|
67
72
|
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
taskqueue/__init__.py,sha256=gVDUAurwUijthE9_36FmhAQTBf7veGgjnew-amrTrmg,241
|
|
2
|
-
taskqueue/celery_app.py,sha256=dUT-7XzsSQbr8vKrLv7f_6iYxTCUEJZHEt9fL-KIQ5U,3302
|
|
3
|
-
taskqueue/cmanager.py,sha256=pBxHi3FT2zuiM3iaMII6KPLYR7DOJmShQH4bzi1xkAU,11076
|
|
4
|
-
taskqueue/libs/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
-
taskqueue/libs/helper_test.py,sha256=_yfPhm_7CzbN30j7E_Ld5KwXRlGHhTNrRTOBZQySEIU,3656
|
|
6
|
-
p1_taskqueue-0.1.6.dist-info/METADATA,sha256=B29pPPy3lL9ubU1TBuXbW_HUFPewzBDAPfB5zSTmKss,1508
|
|
7
|
-
p1_taskqueue-0.1.6.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
8
|
-
p1_taskqueue-0.1.6.dist-info/top_level.txt,sha256=hA3SM1ik2K8iPqtlt_-_nJ4TAePwHPN3vsOc4EiynqU,10
|
|
9
|
-
p1_taskqueue-0.1.6.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|