Skip to content

Commit

Permalink
docs: clarify how to use ASYNCHRONOUS write (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
bednar committed May 6, 2020
1 parent a1f9826 commit 58f653a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
19 changes: 13 additions & 6 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -397,13 +397,17 @@ Data are writes in an asynchronous HTTP request.

.. code-block:: python
from influxdb_client import InfluxDBClient
from influxdb_client import InfluxDBClient, Point
from influxdb_client.client.write_api import ASYNCHRONOUS
client = InfluxDBClient(url="http://localhost:9999", token="my-token", org="my-org")
write_client = client.write_api(write_options=ASYNCHRONOUS)
write_api = client.write_api(write_options=ASYNCHRONOUS)
_point1 = Point("my_measurement").tag("location", "Prague").field("temperature", 25.3)
_point2 = Point("my_measurement").tag("location", "New York").field("temperature", 24.3)
...
async_result = write_api.write(bucket="my-bucket", record=[_point1, _point2])
async_result.get()
client.__del__()
Expand All @@ -414,13 +418,16 @@ Data are writes in a synchronous HTTP request.

.. code-block:: python
from influxdb_client import InfluxDBClient
from influxdb_client import InfluxDBClient, Point
from influxdb_client .client.write_api import SYNCHRONOUS
client = InfluxDBClient(url="http://localhost:9999", token="my-token", org="my-org")
write_client = client.write_api(write_options=SYNCHRONOUS)
write_api = client.write_api(write_options=SYNCHRONOUS)
_point1 = Point("my_measurement").tag("location", "Prague").field("temperature", 25.3)
_point2 = Point("my_measurement").tag("location", "New York").field("temperature", 24.3)
...
write_api.write(bucket="my-bucket", record=[_point1, _point2])
client.__del__()
Expand Down
17 changes: 8 additions & 9 deletions tests/test_WriteApi.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,8 @@ def test_write_dictionaries(self):

_point_list = [_point1, _point2]

self.write_client.write(bucket.name, self.org, _point_list)
time.sleep(1)
async_result = self.write_client.write(bucket.name, self.org, _point_list)
async_result.get()

query = 'from(bucket:"' + bucket.name + '") |> range(start: 1970-01-01T00:00:00.000000001Z)'

Expand Down Expand Up @@ -388,8 +388,8 @@ def test_use_default_tags_with_dictionaries(self):

_point_list = [_point1, _point2]

self.write_client.write(bucket.name, self.org, _point_list)
time.sleep(1)
async_result = self.write_client.write(bucket.name, self.org, _point_list)
async_result.get()

query = 'from(bucket:"' + bucket.name + '") |> range(start: 1970-01-01T00:00:00.000000001Z)'

Expand Down Expand Up @@ -424,10 +424,9 @@ def test_use_default_tags_with_data_frame(self):
index=[now + timedelta(hours=1), now + timedelta(hours=2)],
columns=["location", "water_level"])

self.write_client.write(bucket.name, record=data_frame, data_frame_measurement_name='h2o_feet',
async_result = self.write_client.write(bucket.name, record=data_frame, data_frame_measurement_name='h2o_feet',
data_frame_tag_columns=['location'])

time.sleep(1)
async_result.get()

query = 'from(bucket:"' + bucket.name + '") |> range(start: 1970-01-01T00:00:00.000000001Z)'

Expand Down Expand Up @@ -460,8 +459,8 @@ def test_write_bytes(self):

_bytes_list = [_bytes1, _bytes2]

self.write_client.write(bucket.name, self.org, _bytes_list, write_precision=WritePrecision.S)
time.sleep(1)
async_result = self.write_client.write(bucket.name, self.org, _bytes_list, write_precision=WritePrecision.S)
async_result.get()

query = 'from(bucket:"' + bucket.name + '") |> range(start: 1970-01-01T00:00:00.000000001Z)'

Expand Down

0 comments on commit 58f653a

Please sign in to comment.