p1-taskqueue 0.1.16__tar.gz → 0.1.19__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.
- {p1_taskqueue-0.1.16 → p1_taskqueue-0.1.19}/PKG-INFO +1 -1
- {p1_taskqueue-0.1.16 → p1_taskqueue-0.1.19}/pyproject.toml +1 -1
- {p1_taskqueue-0.1.16 → p1_taskqueue-0.1.19}/src/p1_taskqueue.egg-info/PKG-INFO +1 -1
- {p1_taskqueue-0.1.16 → p1_taskqueue-0.1.19}/src/taskqueue/celery_app.py +1 -1
- {p1_taskqueue-0.1.16 → p1_taskqueue-0.1.19}/src/taskqueue/cmanager.py +1 -1
- {p1_taskqueue-0.1.16 → p1_taskqueue-0.1.19}/src/taskqueue/libs/helper_test.py +7 -2
- {p1_taskqueue-0.1.16 → p1_taskqueue-0.1.19}/tests/test_cmanager.py +5 -5
- {p1_taskqueue-0.1.16 → p1_taskqueue-0.1.19}/tests/test_helper_test_functions.py +71 -0
- {p1_taskqueue-0.1.16 → p1_taskqueue-0.1.19}/README.md +0 -0
- {p1_taskqueue-0.1.16 → p1_taskqueue-0.1.19}/setup.cfg +0 -0
- {p1_taskqueue-0.1.16 → p1_taskqueue-0.1.19}/src/p1_taskqueue.egg-info/SOURCES.txt +0 -0
- {p1_taskqueue-0.1.16 → p1_taskqueue-0.1.19}/src/p1_taskqueue.egg-info/dependency_links.txt +0 -0
- {p1_taskqueue-0.1.16 → p1_taskqueue-0.1.19}/src/p1_taskqueue.egg-info/requires.txt +0 -0
- {p1_taskqueue-0.1.16 → p1_taskqueue-0.1.19}/src/p1_taskqueue.egg-info/top_level.txt +0 -0
- {p1_taskqueue-0.1.16 → p1_taskqueue-0.1.19}/src/taskqueue/__init__.py +0 -0
- {p1_taskqueue-0.1.16 → p1_taskqueue-0.1.19}/src/taskqueue/libs/__init__.py +0 -0
- {p1_taskqueue-0.1.16 → p1_taskqueue-0.1.19}/src/taskqueue/slack_notifier.py +0 -0
- {p1_taskqueue-0.1.16 → p1_taskqueue-0.1.19}/tests/test_celery_app.py +0 -0
- {p1_taskqueue-0.1.16 → p1_taskqueue-0.1.19}/tests/test_return_values.py +0 -0
- {p1_taskqueue-0.1.16 → p1_taskqueue-0.1.19}/tests/test_test_utils.py +0 -0
|
@@ -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.
|
|
8
|
+
version = "0.1.19"
|
|
9
9
|
description = "A Task Queue Wrapper for Dekoruma Backend"
|
|
10
10
|
authors = [
|
|
11
11
|
{name = "Chalvin", email = "engineering@dekoruma.com"}
|
|
@@ -171,7 +171,7 @@ class CManager:
|
|
|
171
171
|
enqueue_op_type, args, kwargs)
|
|
172
172
|
|
|
173
173
|
use_legacy_executor = queue_options.pop(
|
|
174
|
-
'use_legacy_executor',
|
|
174
|
+
'use_legacy_executor', False)
|
|
175
175
|
|
|
176
176
|
if use_legacy_executor:
|
|
177
177
|
task_name, task_args, task_kwargs = _build_dynamic_task_call(
|
|
@@ -112,6 +112,7 @@ def celery_worker_burst(include_func_names: List[str], channel: str = "default")
|
|
|
112
112
|
def get_queued_tasks(channel: str = "default"):
|
|
113
113
|
app = current_app
|
|
114
114
|
queued_tasks = []
|
|
115
|
+
messages = []
|
|
115
116
|
|
|
116
117
|
try:
|
|
117
118
|
with app.connection_for_read() as conn:
|
|
@@ -119,10 +120,11 @@ def get_queued_tasks(channel: str = "default"):
|
|
|
119
120
|
queue = app.amqp.queues[channel](chan)
|
|
120
121
|
|
|
121
122
|
while True:
|
|
122
|
-
message = queue.get(no_ack=
|
|
123
|
+
message = queue.get(no_ack=False)
|
|
123
124
|
if not message:
|
|
124
125
|
break
|
|
125
126
|
|
|
127
|
+
messages.append(message)
|
|
126
128
|
task_name = message.headers.get("task")
|
|
127
129
|
|
|
128
130
|
try:
|
|
@@ -173,7 +175,10 @@ def get_queued_tasks(channel: str = "default"):
|
|
|
173
175
|
|
|
174
176
|
except Exception as e:
|
|
175
177
|
logger.warning(f"Failed to decode message: {e}")
|
|
176
|
-
|
|
178
|
+
|
|
179
|
+
for message in messages:
|
|
180
|
+
if message and not message.acknowledged:
|
|
181
|
+
message.reject(requeue=True)
|
|
177
182
|
|
|
178
183
|
except Exception as e:
|
|
179
184
|
logger.error(
|
|
@@ -365,7 +365,7 @@ class TestCManager:
|
|
|
365
365
|
|
|
366
366
|
mock_send_task.assert_called_once()
|
|
367
367
|
call_args = mock_send_task.call_args
|
|
368
|
-
assert call_args[0][0] == "taskqueue.cmanager.
|
|
368
|
+
assert call_args[0][0] == "taskqueue.cmanager.callable_executor"
|
|
369
369
|
|
|
370
370
|
@patch('taskqueue.cmanager.logger')
|
|
371
371
|
@patch.object(CManager, '_send_task')
|
|
@@ -376,7 +376,7 @@ class TestCManager:
|
|
|
376
376
|
|
|
377
377
|
mock_send_task.assert_called_once()
|
|
378
378
|
call_args = mock_send_task.call_args
|
|
379
|
-
assert call_args[0][0] == "taskqueue.cmanager.
|
|
379
|
+
assert call_args[0][0] == "taskqueue.cmanager.callable_executor"
|
|
380
380
|
|
|
381
381
|
@patch('taskqueue.cmanager.logger')
|
|
382
382
|
@patch.object(CManager, '_send_task')
|
|
@@ -387,7 +387,7 @@ class TestCManager:
|
|
|
387
387
|
|
|
388
388
|
mock_send_task.assert_called_once()
|
|
389
389
|
call_args = mock_send_task.call_args
|
|
390
|
-
assert call_args[0][0] == "taskqueue.cmanager.
|
|
390
|
+
assert call_args[0][0] == "taskqueue.cmanager.callable_executor"
|
|
391
391
|
|
|
392
392
|
def test_cmanager_enqueue_given_no_args_expect_raise_value_error(self):
|
|
393
393
|
cm = CManager()
|
|
@@ -904,13 +904,13 @@ class TestBuildCallableTaskCall:
|
|
|
904
904
|
|
|
905
905
|
@patch('taskqueue.cmanager.logger')
|
|
906
906
|
@patch.object(CManager, '_send_task')
|
|
907
|
-
def
|
|
907
|
+
def test_cmanager_enqueue_given_no_use_legacy_executor_expect_default_to_false(self, mock_send_task: Any, mock_logger: Any) -> None:
|
|
908
908
|
cm = CManager()
|
|
909
909
|
cm.enqueue(test_function, 1, 2)
|
|
910
910
|
|
|
911
911
|
mock_send_task.assert_called_once()
|
|
912
912
|
call_args = mock_send_task.call_args
|
|
913
|
-
assert call_args[0][0] == "taskqueue.cmanager.
|
|
913
|
+
assert call_args[0][0] == "taskqueue.cmanager.callable_executor"
|
|
914
914
|
|
|
915
915
|
@patch('taskqueue.cmanager.logger')
|
|
916
916
|
@patch.object(CManager, '_send_task')
|
|
@@ -220,6 +220,77 @@ class TestHelperTest:
|
|
|
220
220
|
assert result[0]['args'] == []
|
|
221
221
|
assert result[0]['kwargs']['callable_obj'] == bound_method
|
|
222
222
|
|
|
223
|
+
@patch('taskqueue.libs.helper_test.current_app')
|
|
224
|
+
@patch('taskqueue.libs.helper_test.loads')
|
|
225
|
+
def test_get_queued_tasks_expect_messages_are_nacked(self, mock_loads, mock_current_app):
|
|
226
|
+
mock_message1 = MagicMock()
|
|
227
|
+
mock_message1.headers = {
|
|
228
|
+
'task': 'taskqueue.cmanager.dynamic_function_executor'}
|
|
229
|
+
mock_message1.body = b'mock_body'
|
|
230
|
+
mock_message1.content_type = 'application/json'
|
|
231
|
+
mock_message1.content_encoding = 'utf-8'
|
|
232
|
+
mock_message1.acknowledged = False
|
|
233
|
+
|
|
234
|
+
mock_message2 = MagicMock()
|
|
235
|
+
mock_message2.headers = {
|
|
236
|
+
'task': 'taskqueue.cmanager.dynamic_function_executor'}
|
|
237
|
+
mock_message2.body = b'mock_body'
|
|
238
|
+
mock_message2.content_type = 'application/json'
|
|
239
|
+
mock_message2.content_encoding = 'utf-8'
|
|
240
|
+
mock_message2.acknowledged = False
|
|
241
|
+
|
|
242
|
+
mock_loads.return_value = [[], {
|
|
243
|
+
'module_path': 'my.module',
|
|
244
|
+
'function_name': 'my_function',
|
|
245
|
+
'args': [],
|
|
246
|
+
'kwargs': {}
|
|
247
|
+
}]
|
|
248
|
+
|
|
249
|
+
mock_queue = MagicMock()
|
|
250
|
+
mock_queue.get.side_effect = [mock_message1, mock_message2, None]
|
|
251
|
+
mock_current_app.amqp.queues = {
|
|
252
|
+
'default': MagicMock(return_value=mock_queue)}
|
|
253
|
+
|
|
254
|
+
mock_conn = MagicMock()
|
|
255
|
+
mock_chan = MagicMock()
|
|
256
|
+
mock_current_app.connection_for_read.return_value.__enter__.return_value = mock_conn
|
|
257
|
+
mock_conn.channel.return_value.__enter__.return_value = mock_chan
|
|
258
|
+
|
|
259
|
+
result = get_queued_tasks('default')
|
|
260
|
+
|
|
261
|
+
assert len(result) == 2
|
|
262
|
+
mock_message1.reject.assert_called_once_with(requeue=True)
|
|
263
|
+
mock_message2.reject.assert_called_once_with(requeue=True)
|
|
264
|
+
mock_queue.get.assert_called_with(no_ack=False)
|
|
265
|
+
|
|
266
|
+
@patch('taskqueue.libs.helper_test.current_app')
|
|
267
|
+
@patch('taskqueue.libs.helper_test.loads')
|
|
268
|
+
def test_get_queued_tasks_given_decode_failure_expect_nack_called(self, mock_loads, mock_current_app):
|
|
269
|
+
mock_message = MagicMock()
|
|
270
|
+
mock_message.headers = {
|
|
271
|
+
'task': 'taskqueue.cmanager.dynamic_function_executor'}
|
|
272
|
+
mock_message.body = b'mock_body'
|
|
273
|
+
mock_message.content_type = 'application/json'
|
|
274
|
+
mock_message.content_encoding = 'utf-8'
|
|
275
|
+
mock_message.acknowledged = False
|
|
276
|
+
|
|
277
|
+
mock_loads.side_effect = ValueError("Failed to decode")
|
|
278
|
+
|
|
279
|
+
mock_queue = MagicMock()
|
|
280
|
+
mock_queue.get.side_effect = [mock_message, None]
|
|
281
|
+
mock_current_app.amqp.queues = {
|
|
282
|
+
'default': MagicMock(return_value=mock_queue)}
|
|
283
|
+
|
|
284
|
+
mock_conn = MagicMock()
|
|
285
|
+
mock_chan = MagicMock()
|
|
286
|
+
mock_current_app.connection_for_read.return_value.__enter__.return_value = mock_conn
|
|
287
|
+
mock_conn.channel.return_value.__enter__.return_value = mock_chan
|
|
288
|
+
|
|
289
|
+
result = get_queued_tasks('default')
|
|
290
|
+
|
|
291
|
+
assert result == []
|
|
292
|
+
mock_message.reject.assert_called_once_with(requeue=True)
|
|
293
|
+
|
|
223
294
|
@patch('taskqueue.libs.helper_test.get_queued_tasks')
|
|
224
295
|
def test_is_task_in_queue_given_task_exists_expect_true(self, mock_get_queued_tasks):
|
|
225
296
|
mock_get_queued_tasks.return_value = [
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|