in hpcpack-autoscaler/src/cyclecloud-hpcpack/hpcnodehistory.py [0:0]
def reload(self) -> None:
nodehistory = {}
if os.path.exists(self.__statefile):
try:
with open(self.__statefile, 'r') as f:
encodedContent = f.read()
nodehistory = jsonpickle.decode(encodedContent)
except Exception as ex:
logging.warning("Failed to load history information from {}: {}".format(self.__statefile, ex))
if nodehistory:
# If file was updated 7 days ago, do not load it
if nodehistory["updated"] + timedelta(days=7) > datetime.utcnow() and nodehistory["updated"] < datetime.utcnow():
self.__items.clear()
try:
items: List[NodeHistoryItem] = nodehistory["items"]
self.__items.extend(items)
# if file was updated 3 minutes ago, the idle_from time is not correct
if nodehistory["updated"] + timedelta(minutes=3) < datetime.utcnow():
logging.warning("The loaded history information was updated 3 minutes before, clear idle_from ...")
for n in self.__items:
if not n.stopped:
n.idle_from = None
logging.info("Loaded node history HpcNodeHistory(updated={}, items={})".format(nodehistory["updated"], self.items))
except:
self.__items.clear()
else:
logging.warning("The loaded history information is out-dated, discard it")