1234567891011121314151617181920212223242526272829 |
- package service
- import (
- "cicv-data-closedloop/common/util"
- "sync"
- )
- var (
- MonitorQueue = make([]MonitorInfo, 0, QueueLength)
- QueueLength = 120
- mu sync.Mutex // 用于保护MonitorQueue的互斥锁
- )
- type MonitorInfo struct {
- Time string
- }
- // CacheMonitorQueue 向MonitorQueue中添加一个新的MonitorInfo实例,如果队列已满,则替换最旧的元素
- func CacheMonitorQueue() {
- mu.Lock()
- defer mu.Unlock()
- // 创建新的MonitorInfo实例,Time字段为当前时间的字符串表示
- // 如果队列长度已经达到上限,移除最旧的元素
- if len(MonitorQueue) >= QueueLength {
- MonitorQueue = MonitorQueue[1:] // 移除第一个元素
- }
- // 将新的MonitorInfo实例添加到队列的末尾
- MonitorQueue = append(MonitorQueue, MonitorInfo{Time: util.GetNowTimeCustom()})
- }
|