This repository has been archived on 2020-09-24. You can view files and clone it, but cannot push or open issues or pull requests.
consumer-scheduler/ip_watchdog.py

25 lines
664 B
Python
Raw Normal View History

2020-05-08 22:21:15 +02:00
#!/usr/bin/env python3
from typing import Tuple
import logging
import socket
from redis_super_storage import RedisSuperStorage
class IPWatchdog:
def __init__(self, redis_store: RedisSuperStorage):
self._redis_store = redis_store
self._host_name = socket.gethostname()
def ip_changed(self) -> Tuple[bool, str]:
old_ip = self._redis_store.current_ip
current_ip = socket.gethostbyname(self._host_name)
if current_ip != old_ip:
logging.info(f'IP changed: {old_ip} -> {current_ip}')
self._redis_store.current_ip = current_ip
return True, current_ip
return False, old_ip