Retrying connecting Influxdb at setup (#22567)

* Also retry Influxdb at setup()

* Use event.call_later() for retry setup Influxdb

* Fix max line length in setup() in Influxdb

* Add extra space before comment

* Fix sec -> seconds and add return True
This commit is contained in:
Sander Cornelissen 2019-03-31 22:00:48 +02:00 committed by Charles Garwood
parent 5abfc84382
commit 7d7b931163

View File

@ -14,7 +14,7 @@ from homeassistant.const import (
CONF_PASSWORD, CONF_PORT, CONF_SSL, CONF_USERNAME, CONF_VERIFY_SSL, CONF_PASSWORD, CONF_PORT, CONF_SSL, CONF_USERNAME, CONF_VERIFY_SSL,
EVENT_STATE_CHANGED, EVENT_HOMEASSISTANT_STOP, STATE_UNAVAILABLE, EVENT_STATE_CHANGED, EVENT_HOMEASSISTANT_STOP, STATE_UNAVAILABLE,
STATE_UNKNOWN) STATE_UNKNOWN)
from homeassistant.helpers import state as state_helper from homeassistant.helpers import state as state_helper, event as event_helper
import homeassistant.helpers.config_validation as cv import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity_values import EntityValues from homeassistant.helpers.entity_values import EntityValues
@ -39,6 +39,7 @@ DOMAIN = 'influxdb'
TIMEOUT = 5 TIMEOUT = 5
RETRY_DELAY = 20 RETRY_DELAY = 20
QUEUE_BACKLOG_SECONDS = 30 QUEUE_BACKLOG_SECONDS = 30
RETRY_INTERVAL = 60 # seconds
BATCH_TIMEOUT = 1 BATCH_TIMEOUT = 1
BATCH_BUFFER_SIZE = 100 BATCH_BUFFER_SIZE = 100
@ -134,11 +135,16 @@ def setup(hass, config):
influx.write_points([]) influx.write_points([])
except (exceptions.InfluxDBClientError, except (exceptions.InfluxDBClientError,
requests.exceptions.ConnectionError) as exc: requests.exceptions.ConnectionError) as exc:
_LOGGER.error("Database host is not accessible due to '%s', please " _LOGGER.warning(
"check your entries in the configuration file (host, " "Database host is not accessible due to '%s', please "
"port, etc.) and verify that the database exists and is " "check your entries in the configuration file (host, "
"READ/WRITE", exc) "port, etc.) and verify that the database exists and is "
return False "READ/WRITE. Retrying again in %s seconds.", exc, RETRY_INTERVAL
)
event_helper.call_later(
hass, RETRY_INTERVAL, lambda _: setup(hass, config)
)
return True
def event_to_json(event): def event_to_json(event):
"""Add an event to the outgoing Influx list.""" """Add an event to the outgoing Influx list."""