feat: event_push更新last_ws_pushtime

This commit is contained in:
caoqianming 2023-09-06 08:41:12 +08:00
parent 4e06efdc78
commit 1048fb8d5c
1 changed files with 8 additions and 26 deletions

View File

@ -6,9 +6,7 @@ from asgiref.sync import async_to_sync
from celery import shared_task
import requests
from apps.am.models import Area
from apps.ecm.models import EventCate, Eventdo, Event
from apps.ecm.service import notify_event, snap_and_analyse
from apps.hrm.models import Employee
from apps.ecm.models import EventCate, Event
from apps.opm.models import Opl
from apps.third.dahua import dhClient
from apps.third.xunxi import xxClient
@ -24,8 +22,8 @@ from datetime import timedelta
from apps.ai.main import algo_dict
from datetime import datetime
import uuid
from apps.utils.img import compress_image
from apps.ecm.serializers import EventSerializer
from django.utils import timezone
@shared_task(base=CustomTask)
def store_img(code: str, duration: int):
@ -43,6 +41,7 @@ def store_img(code: str, duration: int):
def update_count_people(i: Area):
from apps.ecm.service import handle_xx_event_3
if i.third_info.get('xx_rail', None):
railId = i.third_info['xx_rail']['id']
json = {"railId": railId, "type": ""}
@ -64,27 +63,6 @@ def update_count_people(i: Area):
return {'count': count_people}
def handle_xx_event_3(name: str, area: Area):
cate = EventCate.objects.filter(code=name).first()
if cate:
# 告警间隔内不触发
last_event = Event.objects.filter(cates=cate, area=area, obj_cate='area').order_by('-create_time').first()
same_allow_minute = cate.same_allow_minute
if same_allow_minute >0 and last_event and last_event.create_time + timedelta(minutes=cate.same_allow_minute) > timezone.now():
return
event = Event()
event.area = area
event.obj_cate = 'area'
event.happen_time = timezone.now()
event.save()
Eventdo.objects.get_or_create(cate=cate, event=event, defaults={
'cate': cate,
'event': event
})
voice_msg = area.name + '下有' + str(area.count_people) + '人,' + cate.name + ',请及时处理'
notify_event(event, voice_msg=voice_msg)
@shared_task
def cal_area_count():
"""
@ -110,6 +88,7 @@ def check_event_timeout():
def opl_task(vc_codes: list, opl_id: str):
"""作业监控任务(废弃)
"""
from apps.ecm.service import snap_and_analyse
start_time = time.time()
opl_cate = Opl.objects.get(id=opl_id).cate
# 找到作业需要加载的算法
@ -146,6 +125,7 @@ def monitor_check(vc_ids = []):
@shared_task(base=CustomTask)
def loop_and_analyse(vc: TDevice, tid: str):
from apps.ecm.service import snap_and_analyse
ckey = 'vchannel_' + vc.id
while cache.get(ckey, {}).get('id', None) == tid:
vc_dict = cache.get(ckey, {})
@ -229,4 +209,6 @@ def event_push(eventId: str):
'event': EventSerializer(instance=event).data,
'msg': ''
}
async_to_sync(channel_layer.group_send)('event', data)
async_to_sync(channel_layer.group_send)('event', data)
event.last_ws_pushtime = timezone.now()
event.save()