From b2bf21e6756925d0609ff9d39fe673e070aa2d79 Mon Sep 17 00:00:00 2001 From: shermangriffiths Date: Sun, 8 Dec 2024 15:37:34 -0600 Subject: [PATCH] Patch update the version number, update the README, and and update the retry mechanism --- README.md | 3 +++ n2y/utils.py | 13 +++++++++---- setup.py | 2 +- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index e9d5438..0c4f3c0 100644 --- a/README.md +++ b/README.md @@ -391,6 +391,9 @@ Here are some features we're planning to add in the future: ## Changelog ### v0.10.3 +- Remove the global logger +- Implement exponential backoff for API call retries +- Raise the maximum number of retries to 8 - Add `_get_child_blocks` to the `ExpandingLinkToPageBlock` in the `expandlinktopages.py` plugin and implement it to patch the `Client.get_child_blocks` inside of the `to_pandoc` method. This sets the `page` argument to the `self.page` of the `ExpandingLinkToPageBlock` instance, diff --git a/n2y/utils.py b/n2y/utils.py index 99ca3cf..857cc4e 100644 --- a/n2y/utils.py +++ b/n2y/utils.py @@ -1,6 +1,7 @@ import functools import logging import numbers +import random import re import unicodedata from datetime import datetime @@ -312,10 +313,10 @@ def retry_api_call(api_call): Retry an API call if it fails due to a rate limit or server error. Can only be used to decorate methods of the `Client` class. """ - max_api_retries = 4 + max_api_retries = 8 @functools.wraps(api_call) - def wrapper(*args, retry_count=0, **kwargs): + def wrapper(*args, retry_count=0, _retry_after=2, **kwargs): client = args[0] assert "retry_count" not in kwargs, "retry_count is a reserved keyword" try: @@ -335,7 +336,9 @@ def wrapper(*args, retry_count=0, **kwargs): max_api_retries, ) else: - retry_after = 2 + retry_after = _retry_after + _retry_after *= 1.5 + _retry_after += random.uniform(0, 1) client.logger.info( "This API call failed and " "will be retried in %f seconds. Attempt %d of %d.", @@ -344,7 +347,9 @@ def wrapper(*args, retry_count=0, **kwargs): max_api_retries, ) sleep(retry_after) - return wrapper(*args, retry_count=retry_count, **kwargs) + return wrapper( + *args, retry_count=retry_count, _retry_after=_retry_after**kwargs + ) else: raise err diff --git a/setup.py b/setup.py index 5a20d04..03d958a 100644 --- a/setup.py +++ b/setup.py @@ -12,7 +12,7 @@ setup( name="n2y", - version="0.10.2", + version="0.10.3", description=description, long_description=description, long_description_content_type="text/x-rst",