Support for automatic retry
It would be useful if a Central Dogma client has an option to automatically retry a failed request. If a Central Dogma cluster is rolling restarted, a client may receive the following exception.
centraldogma.exceptions.ShuttingDownException: {"exception":"com.linecorp.centraldogma.common.ShuttingDownException","message":""}
As other servers are healthy, a retry request may succeed.
It's been a long time! Thanks for the nice suggestion. As workaround, you are able to use configs param.
- https://github.com/line/centraldogma-python/blob/main/centraldogma/dogma.py#L64
- https://github.com/line/centraldogma-python/blob/main/centraldogma/base_client.py#L29
- https://www.python-httpx.org/advanced/transports/#http-transport
transport = httpx.HTTPTransport(retries=1)
Dogma("baseUrl", "token", transport=transport)
BTW, it is not a good design because of non-agnostic from httpx dependency. kind of syntactic sugar is supposed to be needed. I will handle it.
Dogma("baseUrl", "token", retries=3)
Likewise, max_connections and max_keepalive_connections should be encapsulated.
- https://github.com/line/centraldogma-python/blob/main/tests/test_base_client.py#L31
Happy to see you again. 🙂
transport = httpx.HTTPTransport(retries=1)
TIL. 📝 I didn't know that HTTPX provides retry out of the box. But it seems the feature is limited to the connection level errors.
Requests will be retried the given number of times in case an httpx.ConnectError or an httpx.ConnectTimeout occurs, allowing smoother operation under flaky networks. If you need other forms of retry behaviors, such as handling read/write errors or reacting to 503 Service Unavailable, consider general-purpose tools such as tenacity.
ShuttingDownException will be returned with 503 Service Unstable status. That means we can
't leverage HTTPX retry to send subsequent requests for ShuttingDownException.
it seems the feature is limited to the connection level errors.
Absolutely. To be clear, here are two issues (also expected two PRs). It seems that given number of retries can be used both for connection errors and server errors.