Skip to content

Commit fd3f9cb

Browse files
authored
fix: use Retry-After header value for Retryable error codes (#130)
1 parent 6e053a6 commit fd3f9cb

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
1. [#117](https://github.com/influxdata/influxdb-client-python/pull/117): Fixed appending default tags for single Point
1111
1. [#115](https://github.com/influxdata/influxdb-client-python/pull/115): Fixed serialization of `\n`, `\r` and `\t` to Line Protocol, `=` is valid sign for measurement name
1212
1. [#118](https://github.com/influxdata/influxdb-client-python/issues/118): Fixed serialization of DataFrame with empty (NaN) values
13+
1. [#130](https://github.com/influxdata/influxdb-client-python/pull/130): Use `Retry-After` header value for Retryable error codes
1314

1415
## 1.8.0 [2020-06-19]
1516

influxdb_client/client/write_api.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,11 @@ def _retry_handler(self, exception, source, data):
349349
if isinstance(exception, ApiException):
350350

351351
if exception.status == 429 or exception.status == 503:
352-
_delay = self._jitter_delay() + timedelta(milliseconds=self._write_options.retry_interval)
352+
retry_interval = self._write_options.retry_interval
353+
if exception.headers:
354+
if "Retry-After" in exception.headers:
355+
retry_interval = int(exception.headers.get("Retry-After")) * 1000
356+
_delay = self._jitter_delay() + timedelta(milliseconds=retry_interval)
353357
return self._retryable(data, delay=_delay)
354358

355359
return rx.just(_BatchResponse(exception=exception, data=data))

tests/test_WriteApiBatching.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ def test_jitter_interval(self):
185185

186186
def test_retry_interval(self):
187187
httpretty.register_uri(httpretty.POST, uri="http://localhost/api/v2/write", status=204)
188-
httpretty.register_uri(httpretty.POST, uri="http://localhost/api/v2/write", status=429)
188+
httpretty.register_uri(httpretty.POST, uri="http://localhost/api/v2/write", status=429, adding_headers={'Retry-After': '5'})
189189
httpretty.register_uri(httpretty.POST, uri="http://localhost/api/v2/write", status=503)
190190

191191
self._write_client.write("my-bucket", "my-org",
@@ -199,7 +199,7 @@ def test_retry_interval(self):
199199

200200
self.assertEqual(2, len(httpretty.httpretty.latest_requests))
201201

202-
time.sleep(3)
202+
time.sleep(5)
203203

204204
self.assertEqual(3, len(httpretty.httpretty.latest_requests))
205205

0 commit comments

Comments
 (0)