fixed ip change detection
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Pünkösd Marcell 2020-04-22 04:49:45 +02:00
parent 5f2894e727
commit d32db92bab

16
app.py
View File

@ -57,6 +57,8 @@ def main():
# get the dictionary of the currently available consumers
consumer_list_redis = json.loads((r.get('consumer_list') or b'{}').decode('utf-8'))
logging.debug('Get consumer list from redis: Done')
temp_dict = {}
for uuid, info in consumer_list_redis.items():
ip = info['ip']
try:
@ -78,14 +80,20 @@ def main():
current_ip = r.get('current_ip')
if current_ip:
current_ip = current_ip.decode('utf-8')
if not current_ip: # Not set yet. I this case no update required
current_ip = socket.gethostbyname(host_name)
r.set('current_ip', current_ip.encode('utf-8'))
logging.debug(f"Previous info about the ip address could not be found! Current: {current_ip}")
if current_ip != socket.gethostbyname(host_name):
logging.info('IP changed. Pushing updates...')
elif current_ip != socket.gethostbyname(host_name):
logging.info(f'IP changed: {current_ip} Pushing updates...')
current_ip = socket.gethostbyname(host_name)
r.set('current_ip', current_ip.encode('utf-8'))
# pushing update...
# pushing updates...
keys = r.keys('producer_*')
logging.debug(f'Pushing update to the following producers: ' + ', '.join(k.decode('utf-8') for k in keys))
@ -108,7 +116,7 @@ def main():
logging.warning(f"Could not push update to {key.decode('utf-8')}: {str(e)}")
continue
else:
logging.debug('IP unchanged.')
logging.debug(f'IP unchanged: {current_ip}')
logging.debug('Waiting for next turn')
time.sleep(os.environ.get("RUN_INTERVAL", 30))