File tree Expand file tree Collapse file tree 2 files changed +6
-4
lines changed Expand file tree Collapse file tree 2 files changed +6
-4
lines changed Original file line number Diff line number Diff line change 22
33
44def fetch_all_pages (
5- name : str , fetch_page : Callable [..., List [Any ]], page_limit = 1000
5+ name : str , fetch_page : Callable [..., List [Any ]], rec_limit = 20000
66) -> Callable [..., Iterator [List [Any ]]]:
77 """Returns an iterator that calls fetch_page with an offset that we increment by the number of pages fetched. Stop if page returns empty list."""
88
99 def fetch_all_pages (* args , ** kwargs ) -> Iterator [List [Any ]]:
1010 page_count = 0
11+ recs = 0
1112 while True :
1213 page_count += 1
13- if page_count > page_limit :
14+ if recs > rec_limit :
1415 # Don't want to DOS ourselves...
1516 raise Exception (
16- f"fetch_all_pages({ name } ): fetched more than { page_limit } pages . Consider using a date range to reduce the number of pages fetched."
17+ f"fetch_all_pages({ name } ): fetched more than { rec_limit } items . Consider using adding or adjusting a filter to reduce the number of items fetched."
1718 )
1819 try :
1920 result = fetch_page (
@@ -27,6 +28,7 @@ def fetch_all_pages(*args, **kwargs) -> Iterator[List[Any]]:
2728 ) from err
2829 if not result :
2930 break
31+ recs += len (result )
3032 yield result
3133
3234 return fetch_all_pages
Original file line number Diff line number Diff line change @@ -61,7 +61,7 @@ def never_ending(*args, **kwargs):
6161 results += page
6262
6363 # assert
64- assert "fetched more than 1000 pages " in str (exc_info )
64+ assert "fetched more than 20000 items " in str (exc_info )
6565
6666
6767def test_fetch_all_pages_handle_error ():
You can’t perform that action at this time.
0 commit comments