p1-taskqueue 0.1.3__tar.gz → 0.1.5__tar.gz

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.3
3
+ Version: 0.1.5
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
@@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"
5
5
  [project]
6
6
  name = "p1-taskqueue"
7
7
  # DO NOT CHANGE THIS VERSION - it gets automatically replaced by CI/CD with the git tag version
8
- version = "0.1.3"
8
+ version = "0.1.5"
9
9
  description = "A Task Queue Wrapper for Dekoruma Backend"
10
10
  authors = [
11
11
  {name = "Chalvin", email = "engineering@dekoruma.com"}
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: p1-taskqueue
3
- Version: 0.1.3
3
+ Version: 0.1.5
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
@@ -12,4 +12,5 @@ src/taskqueue/libs/__init__.py
12
12
  src/taskqueue/libs/helper_test.py
13
13
  tests/test_celery_app.py
14
14
  tests/test_cmanager.py
15
+ tests/test_return_values.py
15
16
  tests/test_test_utils.py
@@ -204,13 +204,21 @@ cm = CManager()
204
204
  # Dynamic task executors - handle function and class method execution
205
205
  @shared_task(bind=True, max_retries=K_MAX_RETRY_COUNT)
206
206
  def dynamic_function_executor(self, module_path, function_name, args=None, kwargs=None, retry=None):
207
+ job_id = self.request.id
207
208
  try:
208
209
  module = importlib.import_module(module_path)
209
210
  function = getattr(module, function_name)
210
211
  args = args or []
211
212
  kwargs = kwargs or {}
212
- return function(*args, **kwargs)
213
+ logger.info(
214
+ f"[TaskQueue] Executing dynamic function: {function_name} with args: {args} and kwargs: {kwargs}, job_id: {job_id}")
215
+ function(*args, **kwargs)
216
+ logger.info(
217
+ f"[TaskQueue] Dynamic function execution completed successfully, function_name: {function_name}, args: {args}, kwargs: {kwargs}, job_id: {job_id}")
218
+ return None
213
219
  except Exception as e:
220
+ logger.exception(
221
+ f"[TaskQueue] Error executing dynamic function: {function_name} with args: {args} and kwargs: {kwargs}, error_class: {e.__class__.__name__}, error: {e}, job_id: {job_id}")
214
222
  current_retries = getattr(self.request, 'retries', 0) or 0
215
223
  max_retries = self.max_retries or K_MAX_RETRY_COUNT
216
224
  if isinstance(retry, dict) and 'max_retries' in retry:
@@ -228,6 +236,7 @@ def dynamic_function_executor(self, module_path, function_name, args=None, kwarg
228
236
 
229
237
  @shared_task(bind=True, max_retries=K_MAX_RETRY_COUNT)
230
238
  def dynamic_class_method_executor(self, module_path, class_name, method_name, args=None, kwargs=None, retry=None):
239
+ job_id = self.request.id
231
240
  try:
232
241
  module = importlib.import_module(module_path)
233
242
  class_obj = getattr(module, class_name)
@@ -235,8 +244,15 @@ def dynamic_class_method_executor(self, module_path, class_name, method_name, ar
235
244
  method = getattr(instance, method_name)
236
245
  args = args or []
237
246
  kwargs = kwargs or {}
238
- return method(*args, **kwargs)
247
+ logger.info(
248
+ f"[TaskQueue] Executing dynamic class method: {method_name} with args: {args} and kwargs: {kwargs}, job_id: {job_id}")
249
+ method(*args, **kwargs)
250
+ logger.info(
251
+ f"[TaskQueue] Dynamic class method execution completed successfully, method_name: {method_name}, args: {args}, kwargs: {kwargs}, job_id: {job_id}")
252
+ return None
239
253
  except Exception as e:
254
+ logger.exception(
255
+ f"[TaskQueue] Error executing dynamic class method: {method_name} with args: {args} and kwargs: {kwargs}, error_class: {e.__class__.__name__}, error: {e}, job_id: {job_id}")
240
256
  current_retries = getattr(self.request, 'retries', 0) or 0
241
257
  max_retries = self.max_retries or K_MAX_RETRY_COUNT
242
258
  if isinstance(retry, dict) and 'max_retries' in retry:
@@ -73,7 +73,7 @@ def celery_worker_burst(include_func_names: List[str], channel: str = "default")
73
73
  logger.info(
74
74
  f"Successfully executed task: {full_func_name}")
75
75
  else:
76
- logger.debug(
76
+ logger.info(
77
77
  f"Skipping: {full_func_name or task_name}")
78
78
  message.ack()
79
79
 
@@ -0,0 +1,83 @@
1
+ from taskqueue.cmanager import dynamic_class_method_executor
2
+ from taskqueue.cmanager import dynamic_function_executor
3
+
4
+
5
+ def function_that_returns_value():
6
+ return "function_return_value"
7
+
8
+
9
+ class TestClass:
10
+ def method_that_returns_value(self):
11
+ return "method_return_value"
12
+
13
+
14
+ class TestExecutorReturnValues:
15
+
16
+ def test_dynamic_function_executor_given_function_returns_value_expect_return_none(self):
17
+ result = dynamic_function_executor(
18
+ "tests.test_return_values",
19
+ "function_that_returns_value",
20
+ [],
21
+ {},
22
+ None
23
+ )
24
+
25
+ assert result is None
26
+
27
+ def test_dynamic_class_method_executor_given_method_returns_value_expect_return_none(self):
28
+ result = dynamic_class_method_executor(
29
+ "tests.test_return_values",
30
+ "TestClass",
31
+ "method_that_returns_value",
32
+ [],
33
+ {},
34
+ None
35
+ )
36
+
37
+ assert result is None
38
+
39
+ def test_dynamic_function_executor_given_function_with_side_effects_expect_function_executed_and_return_none(self):
40
+ global function_executed
41
+ function_executed = False
42
+
43
+ def function_with_side_effect():
44
+ global function_executed
45
+ function_executed = True
46
+ return "should_be_ignored"
47
+
48
+ import sys
49
+ sys.modules[__name__].function_with_side_effect = function_with_side_effect
50
+
51
+ result = dynamic_function_executor(
52
+ "tests.test_return_values",
53
+ "function_with_side_effect",
54
+ [],
55
+ {},
56
+ None
57
+ )
58
+
59
+ assert function_executed
60
+ assert result is None
61
+
62
+ def test_dynamic_class_method_executor_given_method_with_side_effects_expect_method_executed_and_return_none(self):
63
+ class TestClassWithSideEffect:
64
+ def __init__(self):
65
+ self.method_executed = False
66
+
67
+ def method_with_side_effect(self):
68
+ self.method_executed = True
69
+ return "should_be_ignored"
70
+
71
+ import sys
72
+ sys.modules[__name__].TestClassWithSideEffect = TestClassWithSideEffect
73
+
74
+ result = dynamic_class_method_executor(
75
+ "tests.test_return_values",
76
+ "TestClassWithSideEffect",
77
+ "method_with_side_effect",
78
+ [],
79
+ {},
80
+ None
81
+ )
82
+
83
+ assert result is None
File without changes
File without changes