|
8 | 8 |
|
9 | 9 | from ._dataset_client import ApifyDatasetClient
|
10 | 10 | from ._key_value_store_client import ApifyKeyValueStoreClient
|
| 11 | +from ._request_queue_client_full import ApifyRequestQueueClientFull |
11 | 12 | from ._request_queue_client_simple import ApifyRequestQueueClientSimple
|
12 | 13 | from apify._utils import docs_group
|
13 | 14 |
|
|
21 | 22 | class ApifyStorageClient(StorageClient):
|
22 | 23 | """Apify storage client."""
|
23 | 24 |
|
| 25 | + def __init__(self, simple_request_queue: bool = True) -> None: |
| 26 | + """Initialize the Apify storage client. |
| 27 | +
|
| 28 | + Args: |
| 29 | + simple_request_queue: If True, the `create_rq_client` will always return `ApifyRequestQueueClientSimple`, |
| 30 | + if false it will return `ApifyRequestQueueClientFull`. Simple client is suitable for single consumer |
| 31 | + scenarios and makes less API calls. Full client is suitable for multiple consumers scenarios at the |
| 32 | + cost of higher API usage |
| 33 | + """ |
| 34 | + self._simple_request_queue = simple_request_queue |
| 35 | + |
24 | 36 | @override
|
25 | 37 | async def create_dataset_client(
|
26 | 38 | self,
|
@@ -74,7 +86,10 @@ async def create_rq_client(
|
74 | 86 |
|
75 | 87 | configuration = configuration or ApifyConfiguration.get_global_configuration()
|
76 | 88 | if isinstance(configuration, ApifyConfiguration):
|
77 |
| - return await ApifyRequestQueueClientSimple.open(id=id, name=name, configuration=configuration) |
| 89 | + if not self._simple_request_queue: |
| 90 | + return await ApifyRequestQueueClientSimple.open(id=id, name=name, configuration=configuration) |
| 91 | + else: |
| 92 | + return await ApifyRequestQueueClientFull.open(id=id, name=name, configuration=configuration) |
78 | 93 |
|
79 | 94 | raise TypeError(
|
80 | 95 | f'Expected "configuration" to be an instance of "apify.Configuration", '
|
|
0 commit comments