Skip to content

Commit

Permalink
Merge pull request #101 from iamjackg/develop
Browse files Browse the repository at this point in the history
Rework retries, bump pyyaml
  • Loading branch information
iamjackg authored Aug 6, 2023
2 parents 9f6db5a + 3961969 commit 7a94591
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased
### Changed
- automatic retries now apply to all errors instead of just 429 HTTP responses
- pinned pyyaml 6.0.1 to avoid issues with cython 3

## 2.2.1 - 2023-07-17
### Fixed
- Local section links are no longer rendered as broken relative links (e.g. `[this section](#section-header)`)
Expand Down
10 changes: 10 additions & 0 deletions md2cf/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,14 @@ def get_parser():
help="markdown files or directories to upload to Confluence. Empty for stdin",
nargs="*",
)
parser.add_argument(
"--max-retries",
action="store",
dest="max_retries",
type=int,
default=4,
help="number of retry attempts if any API call fails",
)

return parser

Expand Down Expand Up @@ -297,6 +305,7 @@ def main():
password=args.password,
token=args.token,
verify=not args.insecure,
max_retries=args.max_retries,
)

if (args.title or args.page_id) and (
Expand Down Expand Up @@ -380,6 +389,7 @@ def main():
something_went_wrong = False
error = None
tui = Md2cfTUI(pages_to_upload)

with tui:
space_info = confluence.get_space(
args.space, additional_expansions=["homepage"]
Expand Down
8 changes: 5 additions & 3 deletions md2cf/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ def __init__(self, kwargs=None):


class MinimalConfluence:
def __init__(self, host, username=None, password=None, token=None, verify=True):
def __init__(
self, host, username=None, password=None, token=None, verify=True, max_retries=4
):
if token is None:
if username is None and password is None:
raise ValueError(
Expand All @@ -47,10 +49,10 @@ def __init__(self, host, username=None, password=None, token=None, verify=True):

adapter = requests.adapters.HTTPAdapter(
max_retries=urllib3.Retry(
total=4,
total=max_retries,
backoff_factor=1,
respect_retry_after_header=True,
status_forcelist=[429],
allowed_methods=None,
)
)
self.api.mount("http://", adapter)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"mistune==0.8.4",
"chardet==5.1.0",
"requests==2.31.0",
"PyYAML==6.0",
"PyYAML==6.0.1",
"gitignorefile==1.1.2",
],
python_requires=">=3.7",
Expand Down

0 comments on commit 7a94591

Please sign in to comment.