zhangzengfei
2024-05-22 dc427359870f641665788ed2cf775d694272792e
减少设备订阅上报的频率
1个文件已修改
16 ■■■■ 已修改文件
service/subscribe.go 16 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/subscribe.go
@@ -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() {
@@ -150,6 +151,11 @@
        // 上报设备
        if subType == vo.SubscribeApe {
            // 设备通知控制频率, 避免频繁, 上级一般会下发秒级的任务, 但设备不会频繁更新,
            if time.Now().Unix()-task.lastExecTime < 60*10 {
                continue
            }
            var notification = vo.DeviceNotification{
                NotificationID:   triggerTime + snowflake.GenerateIdStr(),
                SubscribeID:      task.conf.Id,
@@ -218,4 +224,6 @@
            client.Notify(task.conf.Ext.ReceiveAddr, b)
        }
    }
    task.lastExecTime = time.Now().Unix()
}