p1-taskqueue 0.1.8__py3-none-any.whl → 0.1.10__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.8.dist-info → p1_taskqueue-0.1.10.dist-info}/METADATA +1 -1
- p1_taskqueue-0.1.10.dist-info/RECORD +9 -0
- taskqueue/celery_app.py +8 -3
- taskqueue/libs/helper_test.py +88 -3
- p1_taskqueue-0.1.8.dist-info/RECORD +0 -9
- {p1_taskqueue-0.1.8.dist-info → p1_taskqueue-0.1.10.dist-info}/WHEEL +0 -0
- {p1_taskqueue-0.1.8.dist-info → p1_taskqueue-0.1.10.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=dnoZWV5VpRjDRp1ihebDXWn1F65cUoQ9CWAxQhulIRs,3375
|
|
3
|
+
taskqueue/cmanager.py,sha256=raQwdccYTpWRiW8UGU5OcUEN0jZr9TTlIEnhZGtamiI,12274
|
|
4
|
+
taskqueue/libs/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
+
taskqueue/libs/helper_test.py,sha256=JCdh2S29PpL8RqUxqkcIqwIvr3M9puqHglBZAmfPkuw,7722
|
|
6
|
+
p1_taskqueue-0.1.10.dist-info/METADATA,sha256=_Q0kAXD7K_GYc1zcGcNvsEWOt7zZTNmwbXvGRiaMjQw,1509
|
|
7
|
+
p1_taskqueue-0.1.10.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
8
|
+
p1_taskqueue-0.1.10.dist-info/top_level.txt,sha256=hA3SM1ik2K8iPqtlt_-_nJ4TAePwHPN3vsOc4EiynqU,10
|
|
9
|
+
p1_taskqueue-0.1.10.dist-info/RECORD,,
|
taskqueue/celery_app.py
CHANGED
|
@@ -23,6 +23,7 @@ def create_celery_app():
|
|
|
23
23
|
app_name = getattr(settings, 'TASKQUEUE_APP_NAME', 'taskqueue')
|
|
24
24
|
app = Celery(app_name)
|
|
25
25
|
|
|
26
|
+
# https://docs.celeryq.dev/en/latest/userguide/configuration.html
|
|
26
27
|
celery_config = {
|
|
27
28
|
'broker_url': getattr(settings, 'CELERY_BROKER_URL', 'amqp://localhost:5672//'),
|
|
28
29
|
'result_backend': getattr(settings, 'CELERY_RESULT_BACKEND', 'rpc://localhost:5672//'),
|
|
@@ -30,12 +31,16 @@ def create_celery_app():
|
|
|
30
31
|
'result_serializer': getattr(settings, 'CELERY_RESULT_SERIALIZER', 'pickle'),
|
|
31
32
|
'accept_content': getattr(settings, 'CELERY_ACCEPT_CONTENT', ['pickle']),
|
|
32
33
|
'timezone': getattr(settings, 'CELERY_TIMEZONE', 'UTC+7'),
|
|
33
|
-
'task_track_started': getattr(settings, 'CELERY_TASK_TRACK_STARTED', True),
|
|
34
34
|
'task_time_limit': getattr(settings, 'CELERY_TASK_TIME_LIMIT', 30 * 60),
|
|
35
35
|
'task_soft_time_limit': getattr(settings, 'CELERY_TASK_SOFT_TIME_LIMIT', 25 * 60),
|
|
36
|
-
'
|
|
37
|
-
'
|
|
36
|
+
'task_track_started': True,
|
|
37
|
+
'task_always_eager': False,
|
|
38
|
+
'task_eager_propagates': True,
|
|
38
39
|
'task_acks_late': True,
|
|
40
|
+
'result_extended': True,
|
|
41
|
+
'task_ignore_result': False,
|
|
42
|
+
'task_send_sent_event': True,
|
|
43
|
+
'worker_send_task_events': True,
|
|
39
44
|
'task_reject_on_worker_lost': True,
|
|
40
45
|
'worker_prefetch_multiplier': 1,
|
|
41
46
|
'worker_max_tasks_per_child': 1000,
|
taskqueue/libs/helper_test.py
CHANGED
|
@@ -60,13 +60,16 @@ def celery_worker_burst(include_func_names: List[str], channel: str = "default")
|
|
|
60
60
|
full_func_name = ""
|
|
61
61
|
if task_name.endswith("dynamic_function_executor"):
|
|
62
62
|
module_path = task_kwargs.get('module_path', '')
|
|
63
|
-
function_name = task_kwargs.get(
|
|
64
|
-
|
|
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}"
|
|
65
67
|
elif task_name.endswith("dynamic_class_method_executor"):
|
|
66
68
|
module_path = task_kwargs.get('module_path', '')
|
|
67
69
|
class_name = task_kwargs.get('class_name', '')
|
|
68
70
|
method_name = task_kwargs.get('method_name', '')
|
|
69
|
-
|
|
71
|
+
if module_path and class_name and method_name:
|
|
72
|
+
full_func_name = f"{module_path}.{class_name}.{method_name}"
|
|
70
73
|
|
|
71
74
|
should_execute = full_func_name in included_set if full_func_name else False
|
|
72
75
|
|
|
@@ -91,3 +94,85 @@ def celery_worker_burst(include_func_names: List[str], channel: str = "default")
|
|
|
91
94
|
except Exception as e:
|
|
92
95
|
logger.error(
|
|
93
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)
|
|
@@ -1,9 +0,0 @@
|
|
|
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,,
|
|
File without changes
|
|
File without changes
|