fix: snap_and_analyse时更新缓存

This commit is contained in:
caoqianming 2023-04-15 17:32:58 +08:00
parent 284a36e24c
commit 64bdd72146
2 changed files with 12 additions and 5 deletions

View File

@ -603,16 +603,23 @@ def get_area_from_point(x: int, y: int, floorNo: str, area_fix_id):
def snap_and_analyse(vchannel: TDevice, algo_codes: list, opl: Opl = None):
global_img_o = dhClient.snap(vchannel.code, raise_exception=False)
happen_time = timezone.now()
ckey = 'vchannel_' + vchannel.id
cvalue = cache.get(ckey, {})
if global_img_o is None: # 说明视频抓拍失败
ckey = 'vchannel_' + vchannel.id
cvalue = cache.get(ckey, None)
if cvalue:
try:
cvalue.update({'snap': 'fail', 'snap_time': datetime.strftime("%Y-%m-%d %H:%M:%S")})
cache.set(ckey, cvalue)
cvalue.update({'snap': 'fail', 'snap_time': datetime.now().strftime("%Y-%m-%d %H:%M:%S")})
cache.set(ckey, cvalue, timeout=60)
except:
pass
return
else:
if cvalue:
try:
cvalue.update({'snap': 'success', 'snap_time': datetime.now().strftime("%Y-%m-%d %H:%M:%S")})
cache.set(ckey, cvalue, timeout=60)
except:
pass
ec_codes = ai_analyse_2(algo_codes, global_img=global_img_o) # 算法处理返回的事件结果
if ec_codes:
# 获取本次所有发生事件种类

View File

@ -137,7 +137,7 @@ def monitor_check(vc_ids = []):
ckey = 'vchannel_' + vc.id
if algo_codes:
tid = str(uuid.uuid4())
cache.set(ckey, {'id': tid, 'algo_codes': algo_codes, 'start_time': datetime.strftime("%Y-%m-%d %H:%M:%S")})
cache.set(ckey, {'id': tid, 'algo_codes': algo_codes, 'start_time': datetime.now().strftime("%Y-%m-%d %H:%M:%S")}, timeout=60)
Thread(target=loop_and_analyse, args=(vc, tid), daemon=True).start()
else:
cache.delete(ckey)