tenacity icon indicating copy to clipboard operation
tenacity copied to clipboard

Add dynamic configuration for stop & wait conditions

Open gtors opened this issue 4 years ago • 2 comments

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()

gtors avatar Jul 16 '21 17:07 gtors

⚠️ No release notes detected. Please make sure to use reno to add a changelog entry.

mergify[bot] avatar Jul 16 '21 17:07 mergify[bot]

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

penguinolog avatar Jul 16 '21 21:07 penguinolog