Stéphane Burwash
10/18/2023, 2:59 PMReuben (Matatika)
10/18/2023, 3:11 PMStéphane Burwash
10/18/2023, 3:14 PMReuben (Matatika)
10/18/2023, 3:35 PMratelimit
recommended rush as an alternative (but also hasn't been updated in a while).Stéphane Burwash
10/18/2023, 3:42 PMStéphane Burwash
10/18/2023, 3:46 PMedgar_ramirez_mondragon
10/18/2023, 4:35 PMStéphane Burwash
10/18/2023, 5:23 PMedgar_ramirez_mondragon
10/18/2023, 5:32 PMLimiter can be used as decorator, but you have to provide ahttps://github.com/vutran1710/PyrateLimiter#decoratorfunction that maps the wrapped function's arguments tomapping
function arguments. The mapping function must return either a tuple oflimiter.try_acquire
or just a(str, int)
str
Stéphane Burwash
10/18/2023, 6:08 PMhas_backoff
function works, is it based off the API you are using?edgar_ramirez_mondragon
10/18/2023, 7:01 PMbackoff
field when you hit a rate limit, so I use that to force a backoff in the client.Stéphane Burwash
10/18/2023, 8:36 PMStéphane Burwash
10/18/2023, 8:37 PMedgar_ramirez_mondragon
10/18/2023, 9:09 PMbackoff
library and does not perform exponential backoffStéphane Burwash
10/18/2023, 9:59 PMedgar_ramirez_mondragon
10/18/2023, 10:13 PMStéphane Burwash
10/18/2023, 10:14 PMStéphane Burwash
10/19/2023, 1:18 AMStéphane Burwash
10/19/2023, 1:57 AMStéphane Burwash
10/20/2023, 7:33 PMdef request_decorator(self, func: Callable[..., Any]) -> Callable[..., Any]:
"""Decorate the request method of the stream.
Args:
func: The RESTStream._request method.
Returns:
Decorated method.
"""
return limiter.as_decorator()(self._limiter_mapping)(
super().request_decorator
)(func)
def _limiter_mapping(self, *_args: Any, **_kwargs: Any) -> tuple[str, int]:
return self.tap_name, 1
But what ends up happening is simply that only the super().request_decorator
is appliededgar_ramirez_mondragon
10/20/2023, 7:43 PMBut what ends up happening is simply that only theDo you mean the pyrate_limiter exceptions are not being raised?is appliedsuper().request_decorator
Stéphane Burwash
10/20/2023, 7:43 PMStéphane Burwash
10/20/2023, 7:44 PMdef request_decorator(self, func: Callable[..., Any]) -> Callable[..., Any]:
"""Decorate the request method of the stream.
Args:
func: The RESTStream._request method.
Returns:
Decorated method.
"""
return limiter.as_decorator()(self._limiter_mapping)(
super().request_decorator(func)
# func
)
Testing out, but now it should work 😄Stéphane Burwash
10/20/2023, 7:45 PMStéphane Burwash
10/20/2023, 7:48 PMdef request_decorator(self, func: Callable[..., Any]) -> Callable[..., Any]:
"""Decorate the request method of the stream.
Args:
func: The RESTStream._request method.
Returns:
Decorated method.
"""
return limiter.as_decorator()(self._limiter_mapping)(
super().request_decorator(func)
# func
)
def _limiter_mapping(self, *_args: Any, **_kwargs: Any) -> tuple[str, int]:
return self.tap_name, 1
Note: It's important to note the order here - I want the backoff / error handling to be applied first so that it can handle any errors coming in from the API and only send clean info to the limiterStéphane Burwash
10/25/2023, 12:22 PM