Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retry requests other than GET on CLI retry #28

Merged
merged 3 commits into from
Apr 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/quetz_client/cli.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os
from typing import Optional
from typing import Optional, cast

import fire
from requests.adapters import HTTPAdapter, Retry
Expand Down Expand Up @@ -34,17 +34,21 @@ def get_client(
Allow to retry requests on transient errors and 5xx server
respones.
"""
# Initialize the client
url = url or os.environ["QUETZ_SERVER_URL"]
token = token or os.environ["QUETZ_API_KEY"]
# Initialize the client (do not force the env variables to be set of help on the
# subcommands does not work without setting them)
url = cast(str, url or os.getenv("QUETZ_SERVER_URL", ""))
token = cast(str, token or os.getenv("QUETZ_API_KEY", ""))
client = QuetzClient.from_token(url, token)

# Configure the client with additional flags passed to the CLI
client.session.verify = not insecure
if retry:
# Retry a total of 10 times, starting with an initial backoff of one second.
retry_config = Retry(
total=10, status_forcelist=range(500, 600), backoff_factor=1
total=10,
status_forcelist=range(500, 600),
backoff_factor=1,
allowed_methods=["GET", "POST", "PUT", "DELETE"],
)
adapter = HTTPAdapter(max_retries=retry_config)
client.session.mount(url, adapter)
Expand Down