events: check mtime on geoip database
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
parent
3d577cf15e
commit
c7ed4f7ac1
|
@ -46,14 +46,18 @@ class GeoIPReader:
|
||||||
LOGGER.warning("Failed to load GeoIP database", exc=exc)
|
LOGGER.warning("Failed to load GeoIP database", exc=exc)
|
||||||
|
|
||||||
def __check_expired(self):
|
def __check_expired(self):
|
||||||
"""Check if the geoip database has been opened longer than 8 hours,
|
"""Check if the modification date of the GeoIP database has
|
||||||
and re-open it, as it will probably will have been re-downloaded"""
|
changed, and reload it if so"""
|
||||||
now = time()
|
path = CONFIG.y("geoip")
|
||||||
diff = datetime.fromtimestamp(now) - datetime.fromtimestamp(self.__last_mtime)
|
try:
|
||||||
diff_hours = diff.total_seconds() // 3600
|
mtime = stat(path).st_mtime
|
||||||
if diff_hours >= 8:
|
diff = self.__last_mtime < mtime
|
||||||
LOGGER.info("GeoIP databased loaded too long, re-opening", diff=diff)
|
if diff > 0:
|
||||||
self.__open()
|
LOGGER.info("Found new GeoIP Database, reopening", diff=diff)
|
||||||
|
self.__open()
|
||||||
|
except OSError as exc:
|
||||||
|
LOGGER.warning("Failed to check GeoIP age", exc=exc)
|
||||||
|
return
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def enabled(self) -> bool:
|
def enabled(self) -> bool:
|
||||||
|
|
Reference in New Issue