|
5 | 5 | import warnings |
6 | 6 | from collections.abc import Iterable |
7 | 7 | from queue import Queue |
8 | | -from typing import TYPE_CHECKING, Any |
| 8 | +from typing import TYPE_CHECKING, Any, Literal |
9 | 9 |
|
10 | 10 | from more_itertools import constrained_batches |
11 | 11 |
|
@@ -495,19 +495,39 @@ def list_requests( |
495 | 495 | self, |
496 | 496 | *, |
497 | 497 | limit: int | None = None, |
498 | | - exclusive_start_id: str | None = None, |
| 498 | + filter: list[Literal['pending', 'locked']] | None = None, # noqa: A002 |
499 | 499 | timeout: Timeout = 'medium', |
| 500 | + cursor: str | None = None, |
| 501 | + exclusive_start_id: str | None = None, |
500 | 502 | ) -> ListOfRequests: |
501 | 503 | """List requests in the queue. |
502 | 504 |
|
503 | 505 | https://docs.apify.com/api/v2#/reference/request-queues/request-collection/list-requests |
504 | 506 |
|
505 | 507 | Args: |
506 | 508 | limit: How many requests to retrieve. |
507 | | - exclusive_start_id: All requests up to this one (including) are skipped from the result. |
| 509 | + filter: List of request states to use as a filter. Multiple values mean union of the given filters. |
508 | 510 | timeout: Timeout for the API HTTP request. |
| 511 | + cursor: A token returned in previous API response, to continue listing next page of requests |
| 512 | + exclusive_start_id: (deprecated) All requests up to this one (including) are skipped from the result. |
509 | 513 | """ |
510 | | - request_params = self._build_params(limit=limit, exclusiveStartId=exclusive_start_id, clientKey=self.client_key) |
| 514 | + if exclusive_start_id and cursor: |
| 515 | + raise ValueError('Cannot use both `exclusive_start_id` and `cursor` for paginating requests.') |
| 516 | + |
| 517 | + if exclusive_start_id is not None: |
| 518 | + warnings.warn( |
| 519 | + '`exclusive_start_id` is deprecated for paginating requests. Use pagination using `cursor` instead.', |
| 520 | + DeprecationWarning, |
| 521 | + stacklevel=2, |
| 522 | + ) |
| 523 | + |
| 524 | + request_params = self._build_params( |
| 525 | + limit=limit, |
| 526 | + filter=','.join(filter) if filter else None, |
| 527 | + clientKey=self.client_key, |
| 528 | + exclusiveStartId=exclusive_start_id, |
| 529 | + cursor=cursor, |
| 530 | + ) |
511 | 531 |
|
512 | 532 | response = self._http_client.call( |
513 | 533 | url=self._build_url('requests'), |
@@ -1033,19 +1053,39 @@ async def list_requests( |
1033 | 1053 | self, |
1034 | 1054 | *, |
1035 | 1055 | limit: int | None = None, |
1036 | | - exclusive_start_id: str | None = None, |
| 1056 | + filter: list[Literal['pending', 'locked']] | None = None, # noqa: A002 |
1037 | 1057 | timeout: Timeout = 'medium', |
| 1058 | + cursor: str | None = None, |
| 1059 | + exclusive_start_id: str | None = None, |
1038 | 1060 | ) -> ListOfRequests: |
1039 | 1061 | """List requests in the queue. |
1040 | 1062 |
|
1041 | 1063 | https://docs.apify.com/api/v2#/reference/request-queues/request-collection/list-requests |
1042 | 1064 |
|
1043 | 1065 | Args: |
1044 | 1066 | limit: How many requests to retrieve. |
1045 | | - exclusive_start_id: All requests up to this one (including) are skipped from the result. |
| 1067 | + filter: List of request states to use as a filter. Multiple values mean union of the given filters. |
1046 | 1068 | timeout: Timeout for the API HTTP request. |
| 1069 | + cursor: A token returned in previous API response, to continue listing next page of requests |
| 1070 | + exclusive_start_id: (deprecated) All requests up to this one (including) are skipped from the result. |
1047 | 1071 | """ |
1048 | | - request_params = self._build_params(limit=limit, exclusiveStartId=exclusive_start_id, clientKey=self.client_key) |
| 1072 | + if exclusive_start_id and cursor: |
| 1073 | + raise ValueError('Cannot use both `exclusive_start_id` and `cursor` for paginating requests.') |
| 1074 | + |
| 1075 | + if exclusive_start_id is not None: |
| 1076 | + warnings.warn( |
| 1077 | + '`exclusive_start_id` is deprecated for paginating requests. Use pagination using `cursor` instead.', |
| 1078 | + DeprecationWarning, |
| 1079 | + stacklevel=2, |
| 1080 | + ) |
| 1081 | + |
| 1082 | + request_params = self._build_params( |
| 1083 | + limit=limit, |
| 1084 | + filter=','.join(filter) if filter else None, |
| 1085 | + clientKey=self.client_key, |
| 1086 | + exclusiveStartId=exclusive_start_id, |
| 1087 | + cursor=cursor, |
| 1088 | + ) |
1049 | 1089 |
|
1050 | 1090 | response = await self._http_client.call( |
1051 | 1091 | url=self._build_url('requests'), |
|
0 commit comments