Skip to content

Commit 4495516

Browse files
committed
Remove try/except from the batch_add_requests
1 parent 8909dfd commit 4495516

File tree

2 files changed

+29
-39
lines changed

2 files changed

+29
-39
lines changed

src/apify_client/clients/resource_clients/request_queue.py

Lines changed: 28 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -332,24 +332,20 @@ def batch_add_requests(
332332
for request in request_batch:
333333
unprocessed_requests[request['uniqueKey']] = _get_unprocessed_request_from_request(request)
334334

335-
try:
336-
# Send the batch to the API.
337-
response = self.http_client.call(
338-
url=self._url('requests/batch'),
339-
method='POST',
340-
params=request_params,
341-
json=list(request_batch),
342-
timeout_secs=_MEDIUM_TIMEOUT,
343-
)
344-
345-
response_parsed = parse_date_fields(pluck_data(response.json()))
346-
processed_requests.extend(response_parsed.get('processedRequests', []))
335+
# Send the batch to the API.
336+
response = self.http_client.call(
337+
url=self._url('requests/batch'),
338+
method='POST',
339+
params=request_params,
340+
json=list(request_batch),
341+
timeout_secs=_MEDIUM_TIMEOUT,
342+
)
347343

348-
for processed_request in response_parsed.get('processedRequests', []):
349-
unprocessed_requests.pop(processed_request['uniqueKey'], None)
344+
response_parsed = parse_date_fields(pluck_data(response.json()))
345+
processed_requests.extend(response_parsed.get('processedRequests', []))
350346

351-
except Exception as exc:
352-
logger.warning(f'Error occurred while processing a batch of requests: {exc}')
347+
for processed_request in response_parsed.get('processedRequests', []):
348+
unprocessed_requests.pop(processed_request['uniqueKey'], None)
353349

354350
return {
355351
'processedRequests': processed_requests,
@@ -667,28 +663,22 @@ async def _batch_add_requests_worker(
667663
except asyncio.CancelledError:
668664
break
669665

670-
try:
671-
# Send the batch to the API.
672-
response = await self.http_client.call(
673-
url=self._url('requests/batch'),
674-
method='POST',
675-
params=request_params,
676-
json=list(request_batch),
677-
timeout_secs=_MEDIUM_TIMEOUT,
678-
)
679-
680-
response_parsed = parse_date_fields(pluck_data(response.json()))
681-
processed_requests.extend(response_parsed.get('processedRequests', []))
682-
683-
for processed_request in response_parsed.get('processedRequests', []):
684-
unprocessed_requests.pop(processed_request['uniqueKey'], None)
685-
686-
except Exception as exc:
687-
logger.warning(f'Error occurred while processing a batch of requests: {exc}')
688-
689-
finally:
690-
# Mark the batch as done whether it succeeded or failed.
691-
queue.task_done()
666+
# Send the batch to the API.
667+
response = await self.http_client.call(
668+
url=self._url('requests/batch'),
669+
method='POST',
670+
params=request_params,
671+
json=list(request_batch),
672+
timeout_secs=_MEDIUM_TIMEOUT,
673+
)
674+
675+
response_parsed = parse_date_fields(pluck_data(response.json()))
676+
processed_requests.extend(response_parsed.get('processedRequests', []))
677+
678+
for processed_request in response_parsed.get('processedRequests', []):
679+
unprocessed_requests.pop(processed_request['uniqueKey'], None)
680+
681+
queue.task_done()
692682

693683
return {
694684
'processedRequests': processed_requests,

tests/unit/test_client_timeouts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def assert_timeout(expected_timeout: int, request: Request) -> Response:
116116
(RequestQueueClient, 'delete_request', request_queue._SMALL_TIMEOUT, {'request_id': 123}),
117117
(RequestQueueClient, 'prolong_request_lock', request_queue._MEDIUM_TIMEOUT, {'request_id': 123, 'lock_secs': 1}),
118118
(RequestQueueClient, 'delete_request_lock', request_queue._SMALL_TIMEOUT, {'request_id': 123}),
119-
(RequestQueueClient, 'batch_add_requests', request_queue._MEDIUM_TIMEOUT, {'requests': [{}]}),
119+
(RequestQueueClient, 'batch_add_requests', request_queue._MEDIUM_TIMEOUT, {'requests': [{'uniqueKey': '123'}]}),
120120
(RequestQueueClient, 'batch_delete_requests', request_queue._SMALL_TIMEOUT, {'requests': [{}]}),
121121
(RequestQueueClient, 'list_requests', request_queue._MEDIUM_TIMEOUT, {}),
122122
]

0 commit comments

Comments
 (0)