Fixed stuff
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Pünkösd Marcell 2020-04-17 16:51:27 +02:00
parent aed27cba95
commit d0d6267c74

25
app.py
View File

@ -22,7 +22,6 @@ sentry_sdk.init("https://0a106e104e114bc9a3fa47f9cb0db2f4@sentry.kmlabz.com/10")
def main(): def main():
# set logging preferences # set logging preferences
logging.basicConfig(filename='', level=logging.DEBUG) logging.basicConfig(filename='', level=logging.DEBUG)
@ -78,16 +77,28 @@ def main():
# wait for the next update time # wait for the next update time
if current_ip != socket.gethostbyname(host_name): if current_ip != socket.gethostbyname(host_name):
logging.debug('Check ip : Done') logging.debug('IP changed. Pushing updates...')
current_ip = socket.gethostbyname(host_name) current_ip = socket.gethostbyname(host_name)
keys = redis.keys('producer_*') keys = r.keys('producer_*')
logging.debug('Get producer list from redis: Done')
logging.debug(f'Pushing update to the following producers: ' + ', '.join(k.decode('utf-8') for k in keys))
for key in keys: for key in keys:
ip = redis.get(key) ip = r.get(key)
if not ip: if ip:
ip = ip.decode('utf-8')
else:
continue continue
try:
response = requests.post(f"http://{ip}/ip", json={'uuid': os.environ['LOCAL_UUID'], 'ip': current_ip}) response = requests.post(f"http://{ip}/ip", json={'uuid': os.environ['LOCAL_UUID'], 'ip': current_ip})
logging.debug(response.status_code) logging.debug(f"Pushed update to {key.decode('utf-8')} at {ip}. Response: {response.status_code}")
except requests.exceptions.ConnectionError as e:
logging.warning(f"Could not push update to {key.decode('utf-8')}: {str(e)}")
continue
else:
logging.debug('IP unchanged.')
time.sleep(30) time.sleep(30)