fixed ip change detection
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
5f2894e727
commit
d32db92bab
16
app.py
16
app.py
@ -57,6 +57,8 @@ def main():
|
|||||||
# get the dictionary of the currently available consumers
|
# get the dictionary of the currently available consumers
|
||||||
consumer_list_redis = json.loads((r.get('consumer_list') or b'{}').decode('utf-8'))
|
consumer_list_redis = json.loads((r.get('consumer_list') or b'{}').decode('utf-8'))
|
||||||
logging.debug('Get consumer list from redis: Done')
|
logging.debug('Get consumer list from redis: Done')
|
||||||
|
|
||||||
|
temp_dict = {}
|
||||||
for uuid, info in consumer_list_redis.items():
|
for uuid, info in consumer_list_redis.items():
|
||||||
ip = info['ip']
|
ip = info['ip']
|
||||||
try:
|
try:
|
||||||
@ -78,14 +80,20 @@ def main():
|
|||||||
|
|
||||||
current_ip = r.get('current_ip')
|
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
|
if not current_ip: # Not set yet. I this case no update required
|
||||||
current_ip = socket.gethostbyname(host_name)
|
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):
|
elif current_ip != socket.gethostbyname(host_name):
|
||||||
logging.info('IP changed. Pushing updates...')
|
logging.info(f'IP changed: {current_ip} Pushing updates...')
|
||||||
current_ip = socket.gethostbyname(host_name)
|
current_ip = socket.gethostbyname(host_name)
|
||||||
r.set('current_ip', current_ip.encode('utf-8'))
|
r.set('current_ip', current_ip.encode('utf-8'))
|
||||||
# pushing update...
|
|
||||||
|
# pushing updates...
|
||||||
keys = r.keys('producer_*')
|
keys = r.keys('producer_*')
|
||||||
|
|
||||||
logging.debug(f'Pushing update to the following producers: ' + ', '.join(k.decode('utf-8') for k in keys))
|
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)}")
|
logging.warning(f"Could not push update to {key.decode('utf-8')}: {str(e)}")
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
logging.debug('IP unchanged.')
|
logging.debug(f'IP unchanged: {current_ip}')
|
||||||
|
|
||||||
logging.debug('Waiting for next turn')
|
logging.debug('Waiting for next turn')
|
||||||
time.sleep(os.environ.get("RUN_INTERVAL", 30))
|
time.sleep(os.environ.get("RUN_INTERVAL", 30))
|
||||||
|
Reference in New Issue
Block a user