From 4ff503f1b00885bdc776af35ed67ac210164603e Mon Sep 17 00:00:00 2001 From: caoqianming Date: Wed, 24 Apr 2024 18:20:39 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20update=5Fmpoint=5Fcache=20state=E5=8F=98?= =?UTF-8?q?=E5=8A=A8=E6=88=96=E8=B6=85=E6=97=B6=E6=9B=B4=E6=96=B0=E8=AE=BE?= =?UTF-8?q?=E5=A4=87=E8=BF=90=E8=A1=8C=E7=8A=B6=E6=80=812?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/enm/services.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/apps/enm/services.py b/apps/enm/services.py index 5d36b48f..3c867575 100644 --- a/apps/enm/services.py +++ b/apps/enm/services.py @@ -121,7 +121,8 @@ def update_mpoint_cache(cache_key: str, current_cache_val: dict, last_timex: dat ep_monitored_id = current_cache_val.get("ep_monitored", False) last_data = current_cache_val["last_data"] last_data["pre_val"] = last_data.get("last_val", None) - last_data["pre_timex"] = last_data.get("last_timex", None) + pre_timex = last_data.get("last_timex", None) + last_data["pre_timex"] = pre_timex last_data["pre_mrs"] = last_data.get("last_mrs", None) last_data["last_val"] = last_val if last_mrs: @@ -134,7 +135,7 @@ def update_mpoint_cache(cache_key: str, current_cache_val: dict, last_timex: dat if ep_monitored_id: cache.set(f"equipment_{ep_monitored_id}", {"running_state": last_mrs, "running_state_timex": last_timex}, timeout=None) # 如果state变动则触发函数 - if last_data["pre_mrs"] != last_mrs or (timezone.now()-last_timex).total_seconds()>30: + if last_data["pre_mrs"] != last_mrs or pre_timex is None or (timezone.now()-pre_timex).total_seconds()>30: if ep_belong_id: ctask_run("apps.em.services.shutdown_or_startup", ep_belong_id, last_timex, Equipment.RUNING) if ep_monitored_id: