p1-taskqueue 0.1.7__py3-none-any.whl → 0.1.9__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.7
3
+ Version: 0.1.9
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
@@ -2,8 +2,8 @@ taskqueue/__init__.py,sha256=nNHXIyysNLom9f8of-d__pWJ-YF53Mbrbsb1frPzPPI,298
2
2
  taskqueue/celery_app.py,sha256=dUT-7XzsSQbr8vKrLv7f_6iYxTCUEJZHEt9fL-KIQ5U,3302
3
3
  taskqueue/cmanager.py,sha256=raQwdccYTpWRiW8UGU5OcUEN0jZr9TTlIEnhZGtamiI,12274
4
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,,
5
+ taskqueue/libs/helper_test.py,sha256=JCdh2S29PpL8RqUxqkcIqwIvr3M9puqHglBZAmfPkuw,7722
6
+ p1_taskqueue-0.1.9.dist-info/METADATA,sha256=qZ-f8EpVmzgYwvU76H-PQ6CDPuUWIv0cqVs0FgkgRwk,1508
7
+ p1_taskqueue-0.1.9.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
8
+ p1_taskqueue-0.1.9.dist-info/top_level.txt,sha256=hA3SM1ik2K8iPqtlt_-_nJ4TAePwHPN3vsOc4EiynqU,10
9
+ p1_taskqueue-0.1.9.dist-info/RECORD,,
@@ -58,10 +58,18 @@ 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") 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]}"
61
+ if task_name.endswith("dynamic_function_executor"):
62
+ module_path = task_kwargs.get('module_path', '')
63
+ function_name = task_kwargs.get(
64
+ 'function_name', '')
65
+ if module_path and function_name:
66
+ full_func_name = f"{module_path}.{function_name}"
67
+ elif task_name.endswith("dynamic_class_method_executor"):
68
+ module_path = task_kwargs.get('module_path', '')
69
+ class_name = task_kwargs.get('class_name', '')
70
+ method_name = task_kwargs.get('method_name', '')
71
+ if module_path and class_name and method_name:
72
+ full_func_name = f"{module_path}.{class_name}.{method_name}"
65
73
 
66
74
  should_execute = full_func_name in included_set if full_func_name else False
67
75
 
@@ -86,3 +94,85 @@ def celery_worker_burst(include_func_names: List[str], channel: str = "default")
86
94
  except Exception as e:
87
95
  logger.error(
88
96
  f"Failed to connect to queue {channel}: {type(e).__name__}: {e}")
97
+
98
+
99
+ def get_queued_tasks(channel: str = "default"):
100
+ app = current_app
101
+ queued_tasks = []
102
+
103
+ try:
104
+ with app.connection_for_read() as conn:
105
+ with conn.channel() as chan:
106
+ queue = app.amqp.queues[channel](chan)
107
+
108
+ while True:
109
+ message = queue.get(no_ack=True)
110
+ if not message:
111
+ break
112
+
113
+ task_name = message.headers.get("task")
114
+
115
+ try:
116
+ accept = {"application/json",
117
+ "application/x-python-serialize"}
118
+ decoded_body = loads(
119
+ message.body, message.content_type, message.content_encoding, accept=accept
120
+ )
121
+
122
+ task_args = decoded_body[0] if decoded_body else []
123
+ task_kwargs = decoded_body[1] if len(
124
+ decoded_body) > 1 else {}
125
+
126
+ full_func_name = ""
127
+ if task_name and task_name.endswith("dynamic_function_executor"):
128
+ module_path = task_kwargs.get('module_path', '')
129
+ function_name = task_kwargs.get(
130
+ 'function_name', '')
131
+ if module_path and function_name:
132
+ full_func_name = f"{module_path}.{function_name}"
133
+ elif task_name and task_name.endswith("dynamic_class_method_executor"):
134
+ module_path = task_kwargs.get('module_path', '')
135
+ class_name = task_kwargs.get('class_name', '')
136
+ method_name = task_kwargs.get('method_name', '')
137
+ if module_path and class_name and method_name:
138
+ full_func_name = f"{module_path}.{class_name}.{method_name}"
139
+
140
+ queued_tasks.append({
141
+ 'task_name': task_name,
142
+ 'full_func_name': full_func_name,
143
+ 'args': task_args,
144
+ 'kwargs': task_kwargs,
145
+ 'headers': message.headers
146
+ })
147
+
148
+ except Exception as e:
149
+ logger.warning(f"Failed to decode message: {e}")
150
+ continue
151
+
152
+ except Exception as e:
153
+ logger.error(
154
+ f"Failed to get queued tasks from queue {channel}: {type(e).__name__}: {e}")
155
+
156
+ return queued_tasks
157
+
158
+
159
+ def is_task_in_queue(expected_func_name: str, channel: str = "default"):
160
+ queued_tasks = get_queued_tasks(channel)
161
+ for task in queued_tasks:
162
+ if task['full_func_name'] == expected_func_name:
163
+ return True
164
+ logger.info(
165
+ f"Task {expected_func_name} not found in queue {channel}. Queued tasks: {[task['full_func_name'] for task in queued_tasks]}")
166
+ return False
167
+
168
+
169
+ def assert_task_in_queue(expected_func_name: str, channel: str = "default", msg: str = None):
170
+ if not is_task_in_queue(expected_func_name, channel):
171
+ error_msg = msg or f"Task '{expected_func_name}' not found in queue '{channel}'"
172
+ raise AssertionError(error_msg)
173
+
174
+
175
+ def assert_task_not_in_queue(expected_func_name: str, channel: str = "default", msg: str = None):
176
+ if is_task_in_queue(expected_func_name, channel):
177
+ error_msg = msg or f"Task '{expected_func_name}' found in queue '{channel}'"
178
+ raise AssertionError(error_msg)