|
15 | 15 | from apify_shared.utils import ignore_docs, maybe_extract_enum_member_value
|
16 | 16 | from crawlee import service_locator
|
17 | 17 | from crawlee.events._types import Event, EventMigratingData, EventPersistStateData
|
18 |
| -from crawlee.storage_clients import MemoryStorageClient |
19 | 18 |
|
20 | 19 | from apify._configuration import Configuration
|
21 | 20 | from apify._consts import EVENT_LISTENERS_TIMEOUT
|
|
35 | 34 | from typing_extensions import Self
|
36 | 35 |
|
37 | 36 | from crawlee.proxy_configuration import _NewUrlFunction
|
| 37 | + from crawlee.storage_clients import BaseStorageClient |
38 | 38 |
|
39 | 39 | from apify._models import Webhook
|
40 | 40 |
|
@@ -72,8 +72,8 @@ def __init__(
|
72 | 72 | self._configure_logging = configure_logging
|
73 | 73 | self._apify_client = self.new_client()
|
74 | 74 |
|
75 |
| - # We need to keep both local & cloud storage clients because of the `force_cloud` option. |
76 |
| - self._local_storage_client = MemoryStorageClient.from_config(config=self.config) |
| 75 | + # Create the instance of the cloud storage client, the local storage client is obtained |
| 76 | + # from the service locator. |
77 | 77 | self._cloud_storage_client = ApifyStorageClient.from_config(config=self.config)
|
78 | 78 |
|
79 | 79 | # Set the event manager based on whether the Actor is running on the platform or locally.
|
@@ -159,6 +159,11 @@ def log(self) -> logging.Logger:
|
159 | 159 | """The logging.Logger instance the Actor uses."""
|
160 | 160 | return logger
|
161 | 161 |
|
| 162 | + @property |
| 163 | + def _local_storage_client(self) -> BaseStorageClient: |
| 164 | + """The local storage client the Actor instance uses.""" |
| 165 | + return service_locator.get_storage_client() |
| 166 | + |
162 | 167 | def _raise_if_not_initialized(self) -> None:
|
163 | 168 | if not self._is_initialized:
|
164 | 169 | raise RuntimeError('The Actor was not initialized!')
|
@@ -190,11 +195,9 @@ async def init(self) -> None:
|
190 | 195 | self._is_exiting = False
|
191 | 196 | self._was_final_persist_state_emitted = False
|
192 | 197 |
|
193 |
| - # Register services in the service locator. |
| 198 | + # If the Actor is running on the Apify platform, we set the cloud storage client. |
194 | 199 | if self.is_at_home():
|
195 | 200 | service_locator.set_storage_client(self._cloud_storage_client)
|
196 |
| - else: |
197 |
| - service_locator.set_storage_client(self._local_storage_client) |
198 | 201 |
|
199 | 202 | service_locator.set_event_manager(self.event_manager)
|
200 | 203 | service_locator.set_configuration(self.configuration)
|
@@ -354,7 +357,7 @@ async def open_dataset(
|
354 | 357 | self._raise_if_not_initialized()
|
355 | 358 | self._raise_if_cloud_requested_but_not_configured(force_cloud=force_cloud)
|
356 | 359 |
|
357 |
| - storage_client = self._cloud_storage_client if force_cloud else service_locator.get_storage_client() |
| 360 | + storage_client = self._cloud_storage_client if force_cloud else self._local_storage_client |
358 | 361 |
|
359 | 362 | return await Dataset.open(
|
360 | 363 | id=id,
|
@@ -388,7 +391,7 @@ async def open_key_value_store(
|
388 | 391 | """
|
389 | 392 | self._raise_if_not_initialized()
|
390 | 393 | self._raise_if_cloud_requested_but_not_configured(force_cloud=force_cloud)
|
391 |
| - storage_client = self._cloud_storage_client if force_cloud else service_locator.get_storage_client() |
| 394 | + storage_client = self._cloud_storage_client if force_cloud else self._local_storage_client |
392 | 395 |
|
393 | 396 | return await KeyValueStore.open(
|
394 | 397 | id=id,
|
@@ -425,7 +428,7 @@ async def open_request_queue(
|
425 | 428 | self._raise_if_not_initialized()
|
426 | 429 | self._raise_if_cloud_requested_but_not_configured(force_cloud=force_cloud)
|
427 | 430 |
|
428 |
| - storage_client = self._cloud_storage_client if force_cloud else service_locator.get_storage_client() |
| 431 | + storage_client = self._cloud_storage_client if force_cloud else self._local_storage_client |
429 | 432 |
|
430 | 433 | return await RequestQueue.open(
|
431 | 434 | id=id,
|
|
0 commit comments