tenacity
tenacity copied to clipboard
Add dynamic configuration for stop & wait conditions
This PR adds the ability to configure @retry based on the attributes of a class instance
Simplified use case:
class Service:
def __init__(self, tries):
self.tries = tries
@retry(
retry=retry_if_exception_type(IOError),
stop=stop_after_attempts(attempts=from_attr("tries")),
)
def call_other_service(self):
...
def load_config_from_file_system():
...
def main():
config = load_config_from_file_system()
serivice = Service(config.service.retry_attempts)
serivice.call_other_service()
⚠️ No release notes detected. Please make sure to use reno to add a changelog entry.
looks like it's job for descriptor, not normal decorator. In case of descriptor, owner class will be registered during class construction and owner instance will be sent to Retrying instance. But this is serious change