Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions speedflux/influx.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import sys
import sys, random, time
from urllib3.exceptions import NewConnectionError

from influxdb import InfluxDBClient
Expand All @@ -25,7 +25,7 @@ def client(self):
speedflux.LOG.debug("Client extablished")
return self._client

def init_db(self):
def init_db(self, backoff_in_seconds = 2):

try:
speedflux.LOG.debug("Intitializing Influx Database")
Expand All @@ -44,13 +44,16 @@ def init_db(self):
speedflux.LOG.error(
"Database Init failed for 3rd time. Exiting")
sys.exit()
sleep = (backoff_in_seconds * 2 ** self.retries + random.uniform(0, 1))
self.retries += 1
speedflux.LOG.error(
"Connection to influx host was refused. This likely "
"means that the DB is down or INFLUX_DB_ADDRESS is "
f"incorrect. It's currently '{self.config.INFLUX_DB_ADDRESS}'")
speedflux.LOG.error("Full Error follows\n")
speedflux.LOG.error(bad_host)
speedflux.LOG.info(f"Backing off before retrying. Sleeping for {sleep} seconds")
time.sleep(sleep)
speedflux.LOG.error(f"Retry {self.retries}: Initiliazing DB.")
self.init_db()

Expand Down