Skip to content

Commit 04b0339

Browse files
committed
refactor: drop redundant already-handled guard from single RQ client
1 parent 1fbf352 commit 04b0339

2 files changed

Lines changed: 0 additions & 50 deletions

File tree

src/apify/storage_clients/_apify/_request_queue_single_client.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -198,12 +198,6 @@ async def fetch_next_request(self) -> Request | None:
198198
# head reconciliations, with no recovery path for the caller.
199199
self._requests_in_progress.discard(request_id)
200200
continue
201-
if request.handled_at is not None:
202-
# The request was already handled on the platform (e.g. by another producer). Skip it and
203-
# remember its id for local deduplication, mirroring the shared client's guard.
204-
self._requests_in_progress.discard(request_id)
205-
self._requests_already_handled.add(request_id)
206-
continue
207201
return request
208202
# No request locally and the ones returned from the platform are already in progress.
209203
return None

tests/unit/storage_clients/test_apify_request_queue_client.py

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
import pytest
88

9-
from apify_client._models import Request as ClientRequest
109
from apify_client._models import RequestQueueHead, RequestQueueStats, RequestRegistration
1110
from crawlee.storage_clients.models import RequestQueueMetadata
1211

@@ -145,49 +144,6 @@ async def test_list_head_limit(in_progress_count: int, expected_limit: int) -> N
145144
api_client.list_head.assert_awaited_once_with(limit=expected_limit)
146145

147146

148-
async def test_fetch_next_request_skips_already_handled() -> None:
149-
"""A request the platform reports as already handled must not be returned by `fetch_next_request`."""
150-
client, api_client = _make_single_client()
151-
152-
unique_key = 'https://example.com'
153-
request_id = unique_key_to_request_id(unique_key)
154-
155-
# Head reconciliation returns nothing new.
156-
api_client.list_head = AsyncMock(
157-
return_value=RequestQueueHead(
158-
limit=200,
159-
queue_modified_at=datetime.now(tz=UTC),
160-
had_multiple_clients=False,
161-
items=[],
162-
)
163-
)
164-
# The platform reports this request as already handled.
165-
api_client.get_request = AsyncMock(
166-
return_value=ClientRequest.model_validate(
167-
{
168-
'id': request_id,
169-
'uniqueKey': unique_key,
170-
'url': unique_key,
171-
'method': 'GET',
172-
'headers': {},
173-
'userData': {},
174-
'retryCount': 0,
175-
'noRetry': False,
176-
'handledAt': datetime.now(tz=UTC),
177-
}
178-
)
179-
)
180-
181-
# Seed the local head estimate with the request id.
182-
client._head_requests.append(request_id)
183-
184-
result = await client.fetch_next_request()
185-
186-
assert result is None, 'Already-handled request must not be fetched.'
187-
assert request_id not in client._requests_in_progress, 'Handled request must not be left in progress.'
188-
assert request_id in client._requests_already_handled, 'Handled request id should be cached for deduplication.'
189-
190-
191147
@pytest.mark.parametrize(
192148
'make_client',
193149
[_make_single_client, _make_shared_client],

0 commit comments

Comments
 (0)