et-go 20240919重建
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
1.6 KiB

1 month ago
package group
import (
"gitea.anxinyun.cn/container/common_models/constant/iotaScheme"
"log"
"math"
"time"
)
const (
4 weeks ago
data_active_expire_sec int = 900 // 15分钟
data_report_expire_sec int = 3600 // 1小时
1 month ago
)
// TimeStrategy 测点组合计算 超时时间判断策略
type TimeStrategy struct {
activeExpiredSecs int
reportExpiredSecs int
}
func DefaultExpire() int {
return data_report_expire_sec
}
// FromDimension 返回超期时间(s)
func FromDimension(dimension string) int {
if dimension == "" {
return DefaultExpire()
}
scheme, err := GetConfigHelper().GetIotaScheme(dimension)
if err != nil {
log.Printf("Get IOTA Scheme ERR:%v", err)
}
if scheme.Mode == iotaScheme.ModeResponse {
return int(math.Min(float64(data_active_expire_sec), float64(scheme.IntervalSecs())))
}
return DefaultExpire()
}
type IDueTask interface {
// 设置超期时长
SetTimeout() int
}
type BaseDueTask struct {
// 数据注入时间(任务创建时间)
InjectTime time.Time
// 超期时间
DeadlineTime time.Time
}
func NewBaseDueTask() *BaseDueTask {
return &BaseDueTask{
InjectTime: time.Now(),
}
}
// IsTimeout 是否超期
func (t *BaseDueTask) IsTimeout() bool {
return !t.DeadlineTime.IsZero() && t.DeadlineTime.Before(time.Now())
}
// ElapsedSecs 当前流逝时间
func (t *BaseDueTask) ElapsedSecs() float64 {
return time.Since(t.InjectTime).Seconds()
}
// SetDeadLineTime 设置超期时间线
func (t *BaseDueTask) SetDeadLineTime(secs int) {
t.DeadlineTime = t.InjectTime.Add(time.Second * time.Duration(secs))
}
func (t *BaseDueTask) SetTimeout() int {
return 0
}