Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/crawlee/_autoscaling/snapshotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,11 +305,11 @@ def _snapshot_client(self) -> None:
Only errors produced by a 2nd retry of the API call are considered for snapshotting since earlier errors may
just be caused by a random spike in the number of requests and do not necessarily signify API overloading.
"""
# TODO: This is just a dummy placeholder. It can be implemented once `StorageClient` is ready.
# Attribute `self._client_rate_limit_error_retry_count` will be used here.
# https://github.com/apify/crawlee-python/issues/60
client = service_locator.get_storage_client()

error_count = 0
rate_limit_errors: dict[int, int] = getattr(client, 'rate_limit_errors', {})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need some explanation here... What values can be in rate_limit_errors? What value is going to be there for the MemoryStorageClient (nothing?) and for the ApifyStorageClient? Thanks.

Copy link
Collaborator Author

@Mantisus Mantisus Feb 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For MemoryStorageClient it is empty dict. Since getattr will return the default value if the specified attribute does not exist
For ApifyStorageClient it is rate_limit_errors from https://github.com/apify/apify-client-python/blob/master/src/apify_client/_statistics.py#L15. Relate PR - apify/apify-sdk-python#387

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I came here from apify/apify-sdk-python#387. I'd much prefer to add another method to the storage client interface, along with a dummy implementation (return {}) on the memory storage client.

Then we can avoid the getattr here, which is pretty confusing and non-standard.


error_count = rate_limit_errors.get(self._CLIENT_RATE_LIMIT_ERROR_RETRY_COUNT, 0)
snapshot = ClientSnapshot(error_count=error_count, max_error_count=self._max_client_errors)

snapshots = cast(list[Snapshot], self._client_snapshots)
Expand Down
Loading