alex_dimov
11/18/2022, 3:04 PMReuben (Matatika)
11/18/2022, 3:06 PMnext_page_token_jsonpath
?alex_dimov
11/18/2022, 3:06 PMalex_dimov
11/18/2022, 3:06 PM{
"ok": true,
"logs": [
{
"service_id": 1234567890,
"service_type": "Google Calendar",
"user_id": "U1234ABCD",
"user_name": "Johnny",
"channel": "C1234567890",
"date": "1392163200",
"change_type": "enabled",
"scope": "incoming-webhook"
},
{
"app_id": "2345678901",
"app_type": "Johnny App",
"user_id": "U2345BCDE",
"user_name": "Billy",
"date": "1392163201",
"change_type": "added",
"scope": "chat:write:user,channels:read"
},
{
"service_id": "3456789012",
"service_type": "Airbrake",
"user_id": "U3456CDEF",
"user_name": "Joey",
"channel": "C1234567890",
"date": "1392163202",
"change_type": "disabled",
"reason": "user",
"scope": "incoming-webhook"
}
],
"paging": {
"count": 3,
"total": 3,
"page": 1,
"pages": 1
}
}
Reuben (Matatika)
11/18/2022, 3:14 PMnext_page_token_jsonpath
, it's not applicable here.alex_dimov
11/18/2022, 3:19 PMReuben (Matatika)
11/18/2022, 3:25 PMdef get_next_page_token(
self, response: requests.Response, previous_token: Optional[Any]
) -> Optional[Any]:
data = response.json()
max_page = data["paging"}["pages"]
current_page = data["paging"]["page"]
next_page = None
if current_page < max_page:
next_page = current_page + 1
# ...
return next_page
alex_dimov
11/18/2022, 3:41 PMalex_dimov
11/18/2022, 3:42 PMedgar_ramirez_mondragon
11/18/2022, 3:48 PMalex_dimov
11/18/2022, 3:49 PMReuben (Matatika)
11/18/2022, 3:51 PMalex_dimov
11/18/2022, 3:53 PMalex_dimov
11/18/2022, 4:06 PMReuben (Matatika)
11/18/2022, 4:07 PMalex_dimov
11/18/2022, 4:09 PMalex_dimov
11/18/2022, 4:11 PMReuben (Matatika)
11/18/2022, 4:13 PMRESTStream.get_next_page_token
been removed in a recent version of the SDK? @edgar_ramirez_mondragonalex_dimov
11/18/2022, 4:14 PMedgar_ramirez_mondragon
11/18/2022, 4:15 PMalex_dimov
11/18/2022, 4:16 PMalex_dimov
11/18/2022, 4:22 PMReuben (Matatika)
11/18/2022, 4:22 PMget_new_paginator
is overriding the super
implementation, which does still call `get_next_page_token`: https://github.com/meltano/sdk/blob/b1a2ec4443759be51b76b76d80d3dd7ee72c190d/singer_sdk/streams/rest.py#L479-L496.alex_dimov
11/18/2022, 4:24 PMReuben (Matatika)
11/18/2022, 4:29 PMclass SlackLogsPaginator(JSONPathPaginator):
def get_next(self, response: Response) -> str | None:
...
alex_dimov
11/18/2022, 4:30 PMalex_dimov
11/18/2022, 4:31 PMReuben (Matatika)
11/18/2022, 4:33 PMclass LogsStream(SlackStream):
def get_new_paginator(self):
return SlackLogsPaginator(self.next_page_token_jsonpath)
Reuben (Matatika)
11/18/2022, 4:38 PMAnd I think that logsPaginator should also work with throttling
class SlackLogsPaginator(ThrottledJSONPathPaginator):
def get_next(self, response: Response) -> str | None:
# apply throttling logic
super().get_next(response)
# your custom pagination implementation
...
Reuben (Matatika)
11/18/2022, 4:40 PMalex_dimov
11/18/2022, 4:40 PMalex_dimov
11/18/2022, 4:41 PMReuben (Matatika)
11/18/2022, 4:41 PMalex_dimov
11/18/2022, 4:42 PMalex_dimov
11/18/2022, 4:42 PMalex_dimov
11/18/2022, 4:42 PMReuben (Matatika)
11/18/2022, 4:44 PMsuper
call return value and apply your own custom pagination logic after - the purpose is just to apply the timeout.Reuben (Matatika)
11/18/2022, 4:44 PMThrottledJSONPathPaginator
...alex_dimov
11/18/2022, 4:45 PMReuben (Matatika)
11/18/2022, 4:47 PMalex_dimov
11/18/2022, 4:48 PMalex_dimov
11/18/2022, 4:49 PMalex_dimov
11/18/2022, 4:50 PMReuben (Matatika)
11/18/2022, 4:52 PMalex_dimov
11/18/2022, 4:53 PMReuben (Matatika)
11/18/2022, 4:54 PMget_new_paginator
for the corresponding stream class.alex_dimov
11/18/2022, 4:55 PMalex_dimov
11/18/2022, 4:56 PMReuben (Matatika)
11/18/2022, 4:58 PMThrottled<pagingator-type>
class that uses it, since ThrottledJSONPathPaginator
is for JSONPath implementations only.alex_dimov
11/18/2022, 4:59 PMReuben (Matatika)
11/18/2022, 4:59 PMalex_dimov
11/18/2022, 5:09 PMalex_dimov
11/18/2022, 5:10 PMReuben (Matatika)
11/18/2022, 5:13 PMbool
value from has_more
though (return
statement needs to be indented one level less).alex_dimov
11/18/2022, 5:13 PMalex_dimov
11/18/2022, 5:14 PMalex_dimov
11/18/2022, 5:14 PMReuben (Matatika)
11/18/2022, 5:15 PM