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"
|
2021-12-14 10:49:29 +08:00
|
|
|
"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() {
|
2021-12-14 10:49:29 +08:00
|
|
|
dbs.OnReadyDone(func() {
|
|
|
|
|
goman.New(func() {
|
2022-04-23 12:32:30 +08:00
|
|
|
NewMonitorItemValueTask(1 * time.Hour).Start()
|
2021-12-14 10:49:29 +08:00
|
|
|
})
|
2021-04-29 16:48:09 +08:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// MonitorItemValueTask 节点监控数值任务
|
|
|
|
|
type MonitorItemValueTask struct {
|
2022-04-23 12:32:30 +08:00
|
|
|
BaseTask
|
2021-04-29 16:48:09 +08:00
|
|
|
|
2022-04-23 12:32:30 +08:00
|
|
|
ticker *time.Ticker
|
2021-04-29 16:48:09 +08:00
|
|
|
}
|
|
|
|
|
|
2022-04-23 12:32:30 +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)
|
|
|
|
|
}
|
2022-04-23 12:32:30 +08:00
|
|
|
|
|
|
|
|
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 {
|
2022-04-23 12:32:30 +08:00
|
|
|
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
|
|
|
}
|