Skip to content

Commit

Permalink
artiq_influxdb: use aiohttp.ClientSession. Closes #829
Browse files Browse the repository at this point in the history
  • Loading branch information
sbourdeauducq committed Nov 22, 2017
1 parent 8ebca38 commit f83cf8d
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions artiq/frontend/artiq_influxdb.py
Expand Up @@ -94,26 +94,26 @@ def update(self, k, v):
"too many pending updates", k)

async def _do(self):
while True:
k, v, t = await self._queue.get()
url = self.base_url + "/write"
params = {"u": self.user, "p": self.password, "db": self.database,
"precision": "ms"}
data = "{},dataset={} {} {}".format(
self.table, k, format_influxdb(v), round(t*1e3))
try:
response = await aiohttp.request(
"POST", url, params=params, data=data)
except:
logger.warning("got exception trying to update '%s'",
k, exc_info=True)
else:
if response.status not in (200, 204):
content = (await response.content.read()).decode().strip()
logger.warning("got HTTP status %d "
"trying to update '%s': %s",
response.status, k, content)
response.close()
async with aiohttp.ClientSession() as session:
while True:
k, v, t = await self._queue.get()
url = self.base_url + "/write"
params = {"u": self.user, "p": self.password, "db": self.database,
"precision": "ms"}
data = "{},dataset={} {} {}".format(
self.table, k, format_influxdb(v), round(t*1e3))
try:
response = await session.post(url, params=params, data=data)
except:
logger.warning("got exception trying to update '%s'",
k, exc_info=True)
else:
if response.status not in (200, 204):
content = (await response.content.read()).decode().strip()
logger.warning("got HTTP status %d "
"trying to update '%s': %s",
response.status, k, content)
response.close()


class _Mock:
Expand Down

0 comments on commit f83cf8d

Please sign in to comment.