Skip to content

Commit

Permalink
Patch update the version number, update the README, and and update th…
Browse files Browse the repository at this point in the history
…e retry mechanism
  • Loading branch information
sHermanGriffiths committed Dec 8, 2024
1 parent 4eb2ec2 commit b2bf21e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
13 changes: 9 additions & 4 deletions n2y/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import functools
import logging
import numbers
import random
import re
import unicodedata
from datetime import datetime
Expand Down Expand Up @@ -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:
Expand All @@ -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.",
Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit b2bf21e

Please sign in to comment.