p1-taskqueue 0.1.6__py3-none-any.whl → 0.1.7__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.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: p1-taskqueue
3
- Version: 0.1.6
3
+ Version: 0.1.7
4
4
  Summary: A Task Queue Wrapper for Dekoruma Backend
5
5
  Author-email: Chalvin <engineering@dekoruma.com>
6
6
  Project-URL: Homepage, https://github.com/Dekoruma/p1-taskqueue
@@ -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=_yfPhm_7CzbN30j7E_Ld5KwXRlGHhTNrRTOBZQySEIU,3656
6
+ p1_taskqueue-0.1.7.dist-info/METADATA,sha256=y3FYv9zHOECh2FzdJRBKofYPGvlr1a1A0wUk4B98TyU,1508
7
+ p1_taskqueue-0.1.7.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
8
+ p1_taskqueue-0.1.7.dist-info/top_level.txt,sha256=hA3SM1ik2K8iPqtlt_-_nJ4TAePwHPN3vsOc4EiynqU,10
9
+ p1_taskqueue-0.1.7.dist-info/RECORD,,
taskqueue/__init__.py CHANGED
@@ -7,6 +7,7 @@ __author__ = "Chalvin"
7
7
  __email__ = "engineering@dekoruma.com"
8
8
 
9
9
  from .cmanager import cm
10
+ from .cmanager import taskqueue_class
10
11
  from .celery_app import celery_app
11
12
 
12
- __all__ = ["cm", "celery_app"]
13
+ __all__ = ["cm", "celery_app", "taskqueue_class"]
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 = [module_path, class_name,
67
- method_name, list(args), dict(func_kwargs)]
68
- task_kwargs: Dict[str, Any] = {}
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 = [module_path, function_name, list(args), dict(func_kwargs)]
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
- instance = class_obj()
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 {}
@@ -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,,