Skip to content

Commit f06eb70

Browse files
committed
Review comments
1 parent e6c6fc5 commit f06eb70

File tree

8 files changed

+170
-257
lines changed

8 files changed

+170
-257
lines changed

src/apify/_actor.py

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@
3838
from apify.log import _configure_logging, logger
3939
from apify.storage_clients import ApifyStorageClient
4040
from apify.storage_clients._file_system import ApifyFileSystemStorageClient
41-
from apify.storage_clients._hybrid_apify._storage_client import ApifyHybridStorageClient
41+
from apify.storage_clients._smart_apify._storage_client import SmartApifyStorageClient
42+
from apify.storages import Dataset, KeyValueStore, RequestQueue
4243

4344
if TYPE_CHECKING:
4445
import logging
@@ -50,7 +51,6 @@
5051
from crawlee.proxy_configuration import _NewUrlFunction
5152

5253
from apify._models import Webhook
53-
from apify.storages import Dataset, KeyValueStore, RequestQueue
5454

5555

5656
MainReturnType = TypeVar('MainReturnType')
@@ -238,14 +238,14 @@ def _raise_if_not_initialized(self) -> None:
238238
raise RuntimeError('The Actor was not initialized!')
239239

240240
@cached_property
241-
def _storage_client(self) -> ApifyHybridStorageClient:
241+
def _storage_client(self) -> SmartApifyStorageClient:
242242
"""Storage client used by the actor.
243243
244244
Depending on the initialization of the service locator the client can be created in different ways.
245245
"""
246246
try:
247247
# Nothing was set by the user.
248-
implicit_storage_client = ApifyHybridStorageClient(
248+
implicit_storage_client = SmartApifyStorageClient(
249249
local_storage_client=ApifyFileSystemStorageClient(), cloud_storage_client=ApifyStorageClient()
250250
)
251251
service_locator.set_storage_client(implicit_storage_client)
@@ -259,13 +259,13 @@ def _storage_client(self) -> ApifyHybridStorageClient:
259259

260260
# User set something in the service locator.
261261
storage_client = service_locator.get_storage_client()
262-
if isinstance(storage_client, ApifyHybridStorageClient):
262+
if isinstance(storage_client, SmartApifyStorageClient):
263263
# The client was manually set to the right type in the service locator. This is the explicit way.
264264
return storage_client
265265

266266
if isinstance(storage_client, ApifyStorageClient):
267267
# The cloud storage client was manually set in the service locator.
268-
return ApifyHybridStorageClient(cloud_storage_client=storage_client)
268+
return SmartApifyStorageClient(cloud_storage_client=storage_client)
269269

270270
# The local storage client was manually set in the service locator
271271
if type(storage_client) is FileSystemStorageClient:
@@ -275,7 +275,7 @@ def _storage_client(self) -> ApifyHybridStorageClient:
275275
f'`apify.storage_clients.FileSystemStorageClient` instead.'
276276
)
277277

278-
return ApifyHybridStorageClient(cloud_storage_client=ApifyStorageClient(), local_storage_client=storage_client)
278+
return SmartApifyStorageClient(cloud_storage_client=ApifyStorageClient(), local_storage_client=storage_client)
279279

280280
async def init(self) -> None:
281281
"""Initialize the Actor instance.
@@ -464,7 +464,12 @@ async def open_dataset(
464464
An instance of the `Dataset` class for the given ID or name.
465465
"""
466466
self._raise_if_not_initialized()
467-
return await self._storage_client.open_dataset(id=id, name=name, alias=alias, force_cloud=force_cloud)
467+
return await Dataset.open(
468+
id=id,
469+
name=name,
470+
alias=alias,
471+
storage_client=self._storage_client.get_suitable_storage_client(force_cloud=force_cloud),
472+
)
468473

469474
async def open_key_value_store(
470475
self,
@@ -493,7 +498,12 @@ async def open_key_value_store(
493498
An instance of the `KeyValueStore` class for the given ID or name.
494499
"""
495500
self._raise_if_not_initialized()
496-
return await self._storage_client.open_key_value_store(id=id, name=name, alias=alias, force_cloud=force_cloud)
501+
return await KeyValueStore.open(
502+
id=id,
503+
name=name,
504+
alias=alias,
505+
storage_client=self._storage_client.get_suitable_storage_client(force_cloud=force_cloud),
506+
)
497507

498508
async def open_request_queue(
499509
self,
@@ -524,7 +534,12 @@ async def open_request_queue(
524534
An instance of the `RequestQueue` class for the given ID or name.
525535
"""
526536
self._raise_if_not_initialized()
527-
return await self._storage_client.open_request_queue(id=id, name=name, alias=alias, force_cloud=force_cloud)
537+
return await RequestQueue.open(
538+
id=id,
539+
name=name,
540+
alias=alias,
541+
storage_client=self._storage_client.get_suitable_storage_client(force_cloud=force_cloud),
542+
)
528543

529544
@overload
530545
async def push_data(self, data: dict | list[dict]) -> None: ...

src/apify/storage_clients/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
from ._apify import ApifyStorageClient
44
from ._file_system import ApifyFileSystemStorageClient as FileSystemStorageClient
5-
from ._hybrid_apify import ApifyHybridStorageClient
5+
from ._smart_apify import SmartApifyStorageClient
66

77
__all__ = [
8-
'ApifyHybridStorageClient',
98
'ApifyStorageClient',
109
'FileSystemStorageClient',
1110
'MemoryStorageClient',
11+
'SmartApifyStorageClient',
1212
]

src/apify/storage_clients/_hybrid_apify/__init__.py

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/apify/storage_clients/_hybrid_apify/_storage_client.py

Lines changed: 0 additions & 226 deletions
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from ._storage_client import SmartApifyStorageClient

0 commit comments

Comments
 (0)