提升统计任务容错性,安全加载 local_storage 数据
pull/1300/head
Cookie987 2025-10-14 22:52:11 +08:00
parent 5ee3d7ea43
commit 2318dbadef
1 changed files with 25 additions and 22 deletions

View File

@ -519,6 +519,7 @@ class StatisticOutputTask(AsyncTask):
last_all_time_stat = None last_all_time_stat = None
try:
if "last_full_statistics" in local_storage: if "last_full_statistics" in local_storage:
# 如果存在上次完整统计数据,则使用该数据进行增量统计 # 如果存在上次完整统计数据,则使用该数据进行增量统计
last_stat: Dict[str, Any] = local_storage["last_full_statistics"] # 上次完整统计数据 # type: ignore last_stat: Dict[str, Any] = local_storage["last_full_statistics"] # 上次完整统计数据 # type: ignore
@ -542,6 +543,8 @@ class StatisticOutputTask(AsyncTask):
last_stat_timestamp = datetime.fromtimestamp(last_stat["timestamp"]) # 上次完整统计数据的时间戳 last_stat_timestamp = datetime.fromtimestamp(last_stat["timestamp"]) # 上次完整统计数据的时间戳
self.stat_period = [item for item in self.stat_period if item[0] != "all_time"] # 删除"所有时间"的统计时段 self.stat_period = [item for item in self.stat_period if item[0] != "all_time"] # 删除"所有时间"的统计时段
self.stat_period.append(("all_time", now - last_stat_timestamp, "自部署以来的")) self.stat_period.append(("all_time", now - last_stat_timestamp, "自部署以来的"))
except Exception as e:
logger.warning(f"加载上次完整统计数据失败,进行全量统计,错误信息:{e}")
stat_start_timestamp = [(period[0], now - period[1]) for period in self.stat_period] stat_start_timestamp = [(period[0], now - period[1]) for period in self.stat_period]