p1-taskqueue 0.1.2__py3-none-any.whl → 0.1.4__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.2
3
+ Version: 0.1.4
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=gVDUAurwUijthE9_36FmhAQTBf7veGgjnew-amrTrmg,241
2
+ taskqueue/celery_app.py,sha256=dUT-7XzsSQbr8vKrLv7f_6iYxTCUEJZHEt9fL-KIQ5U,3302
3
+ taskqueue/cmanager.py,sha256=Xh89VbBYclb-RcmaisqEJfezkT-isyWkQ3KHdSpf_aM,9821
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.4.dist-info/METADATA,sha256=uapQZwJie_JNIfgfJM2zLTXpDIsOVZHAB7ffZj9rvjY,1508
7
+ p1_taskqueue-0.1.4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
8
+ p1_taskqueue-0.1.4.dist-info/top_level.txt,sha256=hA3SM1ik2K8iPqtlt_-_nJ4TAePwHPN3vsOc4EiynqU,10
9
+ p1_taskqueue-0.1.4.dist-info/RECORD,,
taskqueue/cmanager.py CHANGED
@@ -209,7 +209,8 @@ def dynamic_function_executor(self, module_path, function_name, args=None, kwarg
209
209
  function = getattr(module, function_name)
210
210
  args = args or []
211
211
  kwargs = kwargs or {}
212
- return function(*args, **kwargs)
212
+ function(*args, **kwargs)
213
+ return None
213
214
  except Exception as e:
214
215
  current_retries = getattr(self.request, 'retries', 0) or 0
215
216
  max_retries = self.max_retries or K_MAX_RETRY_COUNT
@@ -235,7 +236,8 @@ def dynamic_class_method_executor(self, module_path, class_name, method_name, ar
235
236
  method = getattr(instance, method_name)
236
237
  args = args or []
237
238
  kwargs = kwargs or {}
238
- return method(*args, **kwargs)
239
+ method(*args, **kwargs)
240
+ return None
239
241
  except Exception as e:
240
242
  current_retries = getattr(self.request, 'retries', 0) or 0
241
243
  max_retries = self.max_retries or K_MAX_RETRY_COUNT
File without changes
@@ -0,0 +1,88 @@
1
+ import logging
2
+ from typing import List
3
+
4
+ from celery import current_app
5
+ from kombu.serialization import loads
6
+
7
+ logger = logging.getLogger(__name__)
8
+
9
+
10
+ def clear_all_celery_queues():
11
+ app = current_app
12
+ all_queue_names = list(app.amqp.queues.keys())
13
+ with app.connection_for_read() as conn:
14
+ with conn.channel() as chan:
15
+ for queue_name in all_queue_names:
16
+ queue = app.amqp.queues[queue_name](chan)
17
+ queue.purge()
18
+
19
+
20
+ def celery_worker_burst(include_func_names: List[str], channel: str = "default"):
21
+ # This doesn't use celery as celery doesn't support filtering out functions
22
+ # this use kombu to get the message from the queue and then execute the task manually
23
+ app = current_app
24
+ included_set = set(include_func_names)
25
+ processed_count = 0
26
+ executed_count = 0
27
+
28
+ try:
29
+ with app.connection_for_read() as conn:
30
+ with conn.channel() as chan:
31
+ queue = app.amqp.queues[channel](chan)
32
+
33
+ while True:
34
+ message = queue.get(no_ack=False)
35
+ if not message:
36
+ break
37
+
38
+ processed_count += 1
39
+ task_name = message.headers.get("task")
40
+
41
+ if not task_name or task_name not in app.tasks:
42
+ # task is not registered in celery
43
+ logger.warning(
44
+ f"Invalid task '{task_name}'. Skipping.")
45
+ message.ack()
46
+ continue
47
+
48
+ try:
49
+ task_obj = app.tasks[task_name]
50
+ accept = {"application/json",
51
+ "application/x-python-serialize"}
52
+ decoded_body = loads(
53
+ message.body, message.content_type, message.content_encoding, accept=accept
54
+ )
55
+
56
+ task_args = decoded_body[0] if decoded_body else []
57
+ task_kwargs = decoded_body[1] if len(
58
+ decoded_body) > 1 else {}
59
+
60
+ full_func_name = ""
61
+ if task_name.endswith("dynamic_function_executor") and len(task_args) >= 2:
62
+ full_func_name = f"{task_args[0]}.{task_args[1]}"
63
+ elif task_name.endswith("dynamic_class_method_executor") and len(task_args) >= 3:
64
+ full_func_name = f"{task_args[0]}.{task_args[1]}.{task_args[2]}"
65
+
66
+ should_execute = full_func_name in included_set if full_func_name else False
67
+
68
+ if should_execute:
69
+ logger.info(f"Executing task: {full_func_name}")
70
+ message.ack()
71
+ task_obj.apply(args=task_args, kwargs=task_kwargs)
72
+ executed_count += 1
73
+ logger.info(
74
+ f"Successfully executed task: {full_func_name}")
75
+ else:
76
+ logger.info(
77
+ f"Skipping: {full_func_name or task_name}")
78
+ message.ack()
79
+
80
+ except Exception as e:
81
+ logger.error(
82
+ f"Failed to process task {task_name}: {type(e).__name__}: {e}")
83
+ if message and not message.acknowledged:
84
+ message.ack()
85
+
86
+ except Exception as e:
87
+ logger.error(
88
+ f"Failed to connect to queue {channel}: {type(e).__name__}: {e}")
@@ -1,7 +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=Ec9Z6JgreJWR4p56qO0cAGAjO7d4UJmZ8vVmSOAetms,9795
4
- p1_taskqueue-0.1.2.dist-info/METADATA,sha256=rXHC4CGDgmk0-A57-Fv522-kiNY4scjEGhAQK6kOtU8,1508
5
- p1_taskqueue-0.1.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
6
- p1_taskqueue-0.1.2.dist-info/top_level.txt,sha256=hA3SM1ik2K8iPqtlt_-_nJ4TAePwHPN3vsOc4EiynqU,10
7
- p1_taskqueue-0.1.2.dist-info/RECORD,,