developmentseed / obstore

Simple, fast integration with Amazon S3, Google Cloud Storage, Azure Storage, and S3-compliant APIs like Cloudflare R2
https://developmentseed.org/obstore
MIT License
146 stars 3 forks source link

How to configure backoff retry #92

Closed aldenks closed 18 hours ago

aldenks commented 1 day ago

This package is great to have in the python ecosystem, thank you!

I'm having trouble configuring backoff retries. When I try to do something like the following:

from datetime import timedelta
from obstore.store import HTTPStore

store = HTTPStore.from_url(
    "https://...",
    client_options={
        "connect_timeout": "4",
        "timeout": "16",
    },
    retry_config={
        "max_retries": 10,
        "backoff": {
            "base": 2,
            "init_backoff": timedelta(seconds=1),
            "max_backoff": timedelta(seconds=16),
        },
        "retry_timeout": timedelta(minutes=3),
    },
)

I get

    store = HTTPStore.from_url(
            ^^^^^^^^^^^^^^^^^^^
AttributeError: 'dict' object has no attribute 'backoff'

I also attempted to instantiate the config classes like RetryConfig(max_retries=...) rather than as dict literals, but when I run from obstore.store import RetryConfig, BackoffConfig and variations on that I get an ImportError.

Am I doing something wrong?

kylebarron commented 1 day ago

I haven't tested the backoff config yet, and I think it's a bug on my side where it's trying to call getitem instead of getattr (or maybe I have those two confused). I should fix this, but for now you can test it out with a named tuple and it'll probably work

aldenks commented 14 hours ago

If anyone comes across this, see the test here for an example of how to properly configure https://github.com/developmentseed/obstore/blob/main/tests/test_backoff.py