Ai
1 Star 1 Fork 0

灵狐/go-fox-edge-common

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
RedisStatus.go 1.90 KB
一键复制 编辑 原始数据 按行查看 历史
灵狐 提交于 2024-11-01 17:27 +08:00 . 从内线合并代码到外部
package commRedisStatus
import (
"gitee.com/fierce_wolf/go-fox-edge-common/commUtil/Map"
"gitee.com/fierce_wolf/go-fox-edge-common/commUtil/Number"
"math"
"time"
)
func getActiveTime(modelType string, modelName string) int64 {
consumerData := Consumer.GetValues()
maxActiveTime := int64(0)
for _, val := range consumerData {
if val == nil {
continue
}
value := val.(map[string]interface{})
mType := value[keyModelType]
mName := value[keyModelName]
mTime := value[keyActiveTime]
if mType != modelType || mName != modelName {
continue
}
// 是否存在该activeTime数据
if mTime == nil {
continue
}
tm := Number.MakeInt64(mTime)
// 如果存在,则用来初始化result
if maxActiveTime == 0 {
maxActiveTime = tm
}
maxActiveTime = int64(math.Max(float64(maxActiveTime), float64(tm)))
}
return maxActiveTime
}
func IsActive(modelType string, modelName string, timeout int) bool {
// 通过时间戳,判断通道服务是否正在运行
activeTime := getActiveTime(modelType, modelName)
if activeTime == 0 {
return false
}
now := time.Now().UnixMilli()
return now-activeTime <= int64(timeout)
}
func GetDataList(timeout int64) []map[string]interface{} {
return getDataList(timeout, time.Now().UnixMilli())
}
func getDataList(timeout int64, currentTime int64) []map[string]interface{} {
consumerData := Consumer.GetValues()
resultList := make([]map[string]interface{}, 0)
for _, val := range consumerData {
if val == nil {
continue
}
value := val.(map[string]interface{})
if timeout == -1 {
resultList = append(resultList, value)
continue
}
// 剔除失效的任务:超时超到指定范围的业务
activeTime := Number.MakeInt64(Map.GetOrDefault(value, "activeTime", -1))
if currentTime-activeTime > timeout {
continue
}
value["currentTime"] = currentTime
resultList = append(resultList, value)
}
return resultList
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/fierce_wolf/go-fox-edge-common.git
git@gitee.com:fierce_wolf/go-fox-edge-common.git
fierce_wolf
go-fox-edge-common
go-fox-edge-common
v1.0.1

搜索帮助