-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.py
36 lines (30 loc) · 1.02 KB
/
run.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import daemon
import logging
import requests
import sys
import time
from savemyorchids import fetch_data
from savemyorchids import utils
LOG = logging.getLogger(__name__)
def run():
params = utils.read_config("default")
ping_url = "http://%(host)s:%(port)s/ping" % {"host": params.influx_host,
"port": params.influx_port}
wait_c = 0
timeout = params.wait_for_influx_timeout
step = params.wait_for_influx_step
while wait_c < timeout:
# wait until influxdb accepts connections
try:
data = requests.get(ping_url)
if data.status_code == 204:
break
except requests.exceptions.ConnectionError:
time.sleep(step)
LOG.info("Influxdb unreachable, sleeping for 10 seconds..")
wait_c += step
if wait_c >= timeout:
LOG.error("Influxdb service was unreachable for %s seconds" % timeout)
sys.exit("Influxdb unreachable, exiting")
fetch_data.main()
run()