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

Make requets.Session injectable #16

Merged
merged 1 commit into from
Oct 25, 2023

Conversation

altescy
Copy link
Contributor

@altescy altescy commented Oct 24, 2023

Make requets.Session injectable to configure remote server connections.
In this PR, the session option is added to QueueryClient.__init__ to support retries, etc. as follows:

from requests import Session
from requests.adapters import HTTPAdapter
from urllib3.util.retry import Retry

from queuery_client import QueueryClient

session = Session()
session.mount(
    "https://",
    HTTPAdapter(
        max_retries=Retry(
            connect=2,
            total=5,
            backoff_factor=1,
            status_forcelist=[500, 502, 503, 504],
        ),
    ),
)

client = QueueryClient(session=session)

The given session is passed to the Response object and is used not only to connect to the Queuery server, but also to access unloaded files. Thus, you can write different configurations for the Queuery server / S3, etc.

session.mount(
    "https://queuery.example.com",
    HTTPAdapter(max_retries=Retry(total=3)),
)
session.mount(
    "https://your-bucket.s3.ap-northeast-1.amazonaws.com",
    HTTPAdapter(max_retries=Retry(connect=3, total=5)),
)

@altescy altescy merged commit 54f7725 into bricolages:main Oct 25, 2023
4 checks passed
@altescy altescy deleted the session-injectable branch October 25, 2023 04:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants