Skip to content

Commit

Permalink
fix: use Retry-After header value for Retryable error codes
Browse files Browse the repository at this point in the history
  • Loading branch information
bednar committed Jul 13, 2020
1 parent d2472f4 commit 7c7d70a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
1. [#117](https://github.com/influxdata/influxdb-client-python/pull/117): Fixed appending default tags for single Point
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
1. [#118](https://github.com/influxdata/influxdb-client-python/issues/118): Fixed serialization of DataFrame with empty (NaN) values
1. [#130](https://github.com/influxdata/influxdb-client-python/pull/130): Use `Retry-After` header value for Retryable error codes

## 1.8.0 [2020-06-19]

Expand Down
6 changes: 5 additions & 1 deletion influxdb_client/client/write_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,11 @@ def _retry_handler(self, exception, source, data):
if isinstance(exception, ApiException):

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

return rx.just(_BatchResponse(exception=exception, data=data))
Expand Down
4 changes: 2 additions & 2 deletions tests/test_WriteApiBatching.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def test_jitter_interval(self):

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

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

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

time.sleep(3)
time.sleep(5)

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

Expand Down

0 comments on commit 7c7d70a

Please sign in to comment.