feat: 监控测点掉线函数优化
This commit is contained in:
parent
cb1576b797
commit
35d6d7beb9
|
@ -145,12 +145,17 @@ class MpointCache:
|
|||
cache.set(key, mpoint_data, timeout=None)
|
||||
return mpoint_data
|
||||
|
||||
def set_fail(self, reason: int = -1):
|
||||
def set_fail(self, reason: int = -1, timex: datetime=datetime.now()):
|
||||
"""
|
||||
-1 存库失败 -2 掉线
|
||||
"""
|
||||
self.data['gather_state'] = reason
|
||||
cache.set(self.cache_key, self.data, timeout=None)
|
||||
if reason == -2:
|
||||
is_rep_ep_running_state = self.data.get("is_rep_ep_running_state", False)
|
||||
ep_monitored_id = self.data.get("ep_monitored", None)
|
||||
if is_rep_ep_running_state and ep_monitored_id:
|
||||
set_eq_rs(ep_monitored_id, timex, Equipment.OFFLINE)
|
||||
|
||||
def set(self, last_timex: datetime, last_val):
|
||||
current_cache_val = self.data
|
||||
|
@ -339,7 +344,7 @@ def insert_mplogx_item(code, val, timex, enp_mpoints_dict):
|
|||
pass
|
||||
except Exception:
|
||||
myLogger.error(f"mpoint_code: {code} 存库失败", exc_info=True)
|
||||
mc.set_fail(-1)
|
||||
mc.set_fail(-1, timex)
|
||||
|
||||
|
||||
def insert_mplogx_from_king_mqtt_chunk(objs: list, oval, otime_obj: datetime, is_offset=True):
|
||||
|
|
|
@ -24,6 +24,7 @@ from apps.third.king.king_api import kapis
|
|||
from apps.enm.services import insert_mplogx_from_king_rest_chunk, MpointCache
|
||||
from django.core.cache import cache
|
||||
from django.utils.timezone import localtime
|
||||
from apps.em.services import set_eq_rs
|
||||
|
||||
myLogger = logging.getLogger("log")
|
||||
|
||||
|
@ -745,5 +746,7 @@ def check_mpoint_offline(seconds=100):
|
|||
if last_data and last_data['last_timex'] and (now-last_data['last_timex']).total_seconds() < seconds:
|
||||
is_offline = False
|
||||
if is_offline:
|
||||
mc.set_fail(-2)
|
||||
|
||||
mc.set_fail(-2, now)
|
||||
if mpoint.mpoint_affect:
|
||||
mct = MpointCache(mpoint.mpoint_affect)
|
||||
mct.set_fail(-2, now)
|
Loading…
Reference in New Issue