diff --git a/server/main.py b/server/main.py index 550db40..c2198c6 100644 --- a/server/main.py +++ b/server/main.py @@ -184,7 +184,12 @@ async def history(request): end = int(end.timestamp()) q = 'select * from ecu where time >= {}s and time < {}s'.format(start, end) - history = list(client.query(q).get_points()) + try: + await asyncio.wait_for(asyncio.to_thread(influx_probe.ping), timeout=2) + history = list(client.query(q).get_points()) + except Exception as err: + logging.warning('InfluxDB unavailable for history request: %s', err) + raise web.HTTPServiceUnavailable(text='InfluxDB is not ready') from err return web.json_response(history)