From f946512f64f1e2e9aa887f62f04f8ebedb53d810 Mon Sep 17 00:00:00 2001
From: zhangzengfei <zhangzengfei@smartai.com>
Date: 星期三, 22 五月 2024 15:20:21 +0800
Subject: [PATCH] 优化重传, 修改为每次读取一条记录
---
service/subscribe.go | 31 +++++++++++++++++--------------
1 files changed, 17 insertions(+), 14 deletions(-)
diff --git a/service/subscribe.go b/service/subscribe.go
index 556043e..ccc9b5c 100644
--- a/service/subscribe.go
+++ b/service/subscribe.go
@@ -3,6 +3,7 @@
import (
"context"
"encoding/json"
+ "gat1400Exchange/config"
"strings"
"sync"
"time"
@@ -52,12 +53,12 @@
}
}
-func InitSubscribeTask() error {
+func InitSubscribeTask() {
var s models.Subscribe
- subList, err := s.FindAll()
+ subList, err := s.FindByFromId(config.ClientConf.ServerId)
if err != nil {
- logger.Error("Find account by channel error:%v", err)
- return err
+ logger.Error("Find subscribe error, server id %s, %v", config.ClientConf.ServerId, err)
+ return
}
for idx, _ := range subList {
@@ -68,17 +69,16 @@
CreateTask(&subList[idx])
}
- return nil
+ return
}
-func AddFaceCapture(face *vo.FaceObject) {
+func AddFaceNotification(face *vo.FaceObject) {
TaskProcMap.Range(func(key, value interface{}) bool {
value.(TaskProcInfo).task.AddFace(face)
return true
})
- logger.Debug("娣诲姞浜鸿劯.")
- //TaskWaitGroup.Wait()
+ logger.Debug("Add Face Notification.")
}
func StopSubscribeTask() {
@@ -109,10 +109,11 @@
}
type SubscribeTask struct {
- ctx context.Context
- conf *models.Subscribe
- faceList []*vo.FaceObject
- mutex sync.Mutex
+ ctx context.Context
+ conf *models.Subscribe
+ faceList []*vo.FaceObject
+ mutex sync.Mutex
+ lastExecTime int64
}
func (task *SubscribeTask) Start() {
@@ -148,8 +149,8 @@
for _, subType := range subDetails {
triggerTime := time.Now().Format("20060102150405")
- // 涓婃姤璁惧
- if subType == vo.SubscribeApe {
+ // 涓婃姤璁惧 鎺у埗璁惧閫氱煡鎺у埗棰戠巼, 閬垮厤棰戠箒, 涓婄骇涓�鑸細涓嬪彂绉掔骇鐨勪换鍔�, 浣嗚澶囦笉浼氶绻佹洿鏂�,
+ if subType == vo.SubscribeApe && time.Now().Unix()-task.lastExecTime > 60*10 {
var notification = vo.DeviceNotification{
NotificationID: triggerTime + snowflake.GenerateIdStr(),
SubscribeID: task.conf.Id,
@@ -218,4 +219,6 @@
client.Notify(task.conf.Ext.ReceiveAddr, b)
}
}
+
+ task.lastExecTime = time.Now().Unix()
}
--
Gitblit v1.8.0