Files
EdgeAPI/internal/tasks/monitor_item_value_task.go

53 lines
1.0 KiB
Go
Raw Normal View History

2024-05-17 18:27:26 +08:00
// Copyright 2021 GoEdge CDN goedge.cdn@gmail.com. All rights reserved.
2021-04-29 16:48:09 +08:00
package tasks
import (
2024-07-27 14:15:25 +08:00
"time"
2021-04-29 16:48:09 +08:00
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
"github.com/TeaOSLab/EdgeAPI/internal/goman"
2021-04-29 16:48:09 +08:00
"github.com/iwind/TeaGo/Tea"
"github.com/iwind/TeaGo/dbs"
)
func init() {
dbs.OnReadyDone(func() {
goman.New(func() {
NewMonitorItemValueTask(1 * time.Hour).Start()
})
2021-04-29 16:48:09 +08:00
})
}
// MonitorItemValueTask 节点监控数值任务
type MonitorItemValueTask struct {
BaseTask
2021-04-29 16:48:09 +08:00
ticker *time.Ticker
2021-04-29 16:48:09 +08:00
}
// NewMonitorItemValueTask 获取新对象
func NewMonitorItemValueTask(duration time.Duration) *MonitorItemValueTask {
var ticker = time.NewTicker(duration)
2021-04-29 16:48:09 +08:00
if Tea.IsTesting() {
ticker = time.NewTicker(1 * time.Minute)
}
return &MonitorItemValueTask{
ticker: ticker,
}
}
func (this *MonitorItemValueTask) Start() {
for range this.ticker.C {
2021-04-29 16:48:09 +08:00
err := this.Loop()
if err != nil {
this.logErr("MonitorItemValueTask", err.Error())
2021-04-29 16:48:09 +08:00
}
}
}
func (this *MonitorItemValueTask) Loop() error {
2021-12-06 10:15:32 +08:00
return models.SharedNodeValueDAO.Clean(nil)
2021-04-29 16:48:09 +08:00
}