Skip to content

Commit 98b76c5

Browse files
committed
Addressing more feedback
1 parent 8de950b commit 98b76c5

File tree

4 files changed

+22
-21
lines changed

4 files changed

+22
-21
lines changed
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
from crawlee.storage_clients import FileSystemStorageClient, MemoryStorageClient, StorageClient
1+
from crawlee.storage_clients import FileSystemStorageClient, MemoryStorageClient
22

33
from ._apify import ApifyStorageClient
44

55
__all__ = [
66
'ApifyStorageClient',
77
'FileSystemStorageClient',
88
'MemoryStorageClient',
9-
'StorageClient',
109
]

src/apify/storage_clients/_apify/_dataset_client.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ def __init__(
3333
modified_at: datetime,
3434
item_count: int,
3535
api_client: DatasetClientAsync,
36+
lock: asyncio.Lock,
3637
) -> None:
3738
"""Initialize a new instance.
3839
@@ -50,7 +51,7 @@ def __init__(
5051
self._api_client = api_client
5152
"""The Apify dataset client for API operations."""
5253

53-
self._lock = asyncio.Lock()
54+
self._lock = lock
5455
"""A lock to ensure that only one operation is performed at a time."""
5556

5657
@property
@@ -75,20 +76,19 @@ async def open(
7576
if not api_url:
7677
raise ValueError(f'Apify storage client requires a valid API URL in Configuration (api_url={api_url}).')
7778

78-
# Otherwise, create a new one.
79+
if id and name:
80+
raise ValueError('Only one of "id" or "name" can be specified, not both.')
81+
82+
# Create Apify client with the provided token and API URL.
7983
apify_client_async = ApifyClientAsync(
8084
token=token,
8185
api_url=api_url,
8286
max_retries=8,
8387
min_delay_between_retries_millis=500,
8488
timeout_secs=360,
8589
)
86-
8790
apify_datasets_client = apify_client_async.datasets()
8891

89-
if id and name:
90-
raise ValueError('Only one of "id" or "name" can be specified, not both.')
91-
9292
# If name is provided, get or create the storage by name.
9393
if name is not None and id is None:
9494
id = DatasetMetadata.model_validate(
@@ -118,6 +118,7 @@ async def open(
118118
modified_at=metadata.modified_at,
119119
item_count=metadata.item_count,
120120
api_client=apify_dataset_client,
121+
lock=asyncio.Lock(),
121122
)
122123

123124
@override

src/apify/storage_clients/_apify/_key_value_store_client.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ def __init__(
3636
accessed_at: datetime,
3737
modified_at: datetime,
3838
api_client: KeyValueStoreClientAsync,
39+
lock: asyncio.Lock,
3940
) -> None:
4041
"""Initialize a new instance.
4142
@@ -52,7 +53,7 @@ def __init__(
5253
self._api_client = api_client
5354
"""The Apify key-value store client for API operations."""
5455

55-
self._lock = asyncio.Lock()
56+
self._lock = lock
5657
"""A lock to ensure that only one operation is performed at a time."""
5758

5859
@property
@@ -77,20 +78,19 @@ async def open(
7778
if not api_url:
7879
raise ValueError(f'Apify storage client requires a valid API URL in Configuration (api_url={api_url}).')
7980

80-
# Otherwise, create a new one.
81+
if id and name:
82+
raise ValueError('Only one of "id" or "name" can be specified, not both.')
83+
84+
# Create Apify client with the provided token and API URL.
8185
apify_client_async = ApifyClientAsync(
8286
token=token,
8387
api_url=api_url,
8488
max_retries=8,
8589
min_delay_between_retries_millis=500,
8690
timeout_secs=360,
8791
)
88-
8992
apify_kvss_client = apify_client_async.key_value_stores()
9093

91-
if id and name:
92-
raise ValueError('Only one of "id" or "name" can be specified, not both.')
93-
9494
# If name is provided, get or create the storage by name.
9595
if name is not None and id is None:
9696
id = KeyValueStoreMetadata.model_validate(
@@ -119,6 +119,7 @@ async def open(
119119
accessed_at=metadata.accessed_at,
120120
modified_at=metadata.modified_at,
121121
api_client=apify_kvs_client,
122+
lock=asyncio.Lock(),
122123
)
123124

124125
@override

src/apify/storage_clients/_apify/_request_queue_client.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ def __init__(
4949
stats: dict,
5050
total_request_count: int,
5151
api_client: RequestQueueClientAsync,
52+
lock: asyncio.Lock,
5253
) -> None:
5354
"""Initialize a new instance.
5455
@@ -70,7 +71,7 @@ def __init__(
7071
self._api_client = api_client
7172
"""The Apify request queue client for API operations."""
7273

73-
self._lock = asyncio.Lock()
74+
self._lock = lock
7475
"""A lock to ensure that only one operation is performed at a time."""
7576

7677
self._queue_head = deque[str]()
@@ -107,20 +108,19 @@ async def open(
107108
if not api_url:
108109
raise ValueError(f'Apify storage client requires a valid API URL in Configuration (api_url={api_url}).')
109110

110-
# Create a new API client
111+
if id and name:
112+
raise ValueError('Only one of "id" or "name" can be specified, not both.')
113+
114+
# Create Apify client with the provided token and API URL.
111115
apify_client_async = ApifyClientAsync(
112116
token=token,
113117
api_url=api_url,
114118
max_retries=8,
115119
min_delay_between_retries_millis=500,
116120
timeout_secs=360,
117121
)
118-
119122
apify_rqs_client = apify_client_async.request_queues()
120123

121-
if id and name:
122-
raise ValueError('Only one of "id" or "name" can be specified, not both.')
123-
124124
# If name is provided, get or create the storage by name.
125125
if name is not None and id is None:
126126
id = RequestQueueMetadata.model_validate(
@@ -142,7 +142,6 @@ async def open(
142142
# Fetch its metadata.
143143
metadata = RequestQueueMetadata.model_validate(await apify_rq_client.get())
144144

145-
# Create the client instance
146145
return cls(
147146
id=metadata.id,
148147
name=metadata.name,
@@ -155,6 +154,7 @@ async def open(
155154
stats=metadata.stats,
156155
total_request_count=metadata.total_request_count,
157156
api_client=apify_rq_client,
157+
lock=asyncio.Lock(),
158158
)
159159

160160
@override

0 commit comments

Comments
 (0)