mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-10 12:30:24 +08:00
多个API节点时选择一个作为主节点/优化任务相关代码
This commit is contained in:
@@ -5,7 +5,6 @@ package tasks
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/goman"
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/remotelogs"
|
||||
"github.com/iwind/TeaGo/Tea"
|
||||
"github.com/iwind/TeaGo/dbs"
|
||||
"time"
|
||||
@@ -14,29 +13,35 @@ import (
|
||||
func init() {
|
||||
dbs.OnReadyDone(func() {
|
||||
goman.New(func() {
|
||||
NewMonitorItemValueTask().Start()
|
||||
NewMonitorItemValueTask(1 * time.Hour).Start()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// MonitorItemValueTask 节点监控数值任务
|
||||
type MonitorItemValueTask struct {
|
||||
BaseTask
|
||||
|
||||
ticker *time.Ticker
|
||||
}
|
||||
|
||||
// NewMonitorItemValueTask 获取新对象
|
||||
func NewMonitorItemValueTask() *MonitorItemValueTask {
|
||||
return &MonitorItemValueTask{}
|
||||
}
|
||||
|
||||
func (this *MonitorItemValueTask) Start() {
|
||||
ticker := time.NewTicker(1 * time.Hour)
|
||||
func NewMonitorItemValueTask(duration time.Duration) *MonitorItemValueTask {
|
||||
var ticker = time.NewTicker(duration)
|
||||
if Tea.IsTesting() {
|
||||
ticker = time.NewTicker(1 * time.Minute)
|
||||
}
|
||||
for range ticker.C {
|
||||
|
||||
return &MonitorItemValueTask{
|
||||
ticker: ticker,
|
||||
}
|
||||
}
|
||||
|
||||
func (this *MonitorItemValueTask) Start() {
|
||||
for range this.ticker.C {
|
||||
err := this.Loop()
|
||||
if err != nil {
|
||||
remotelogs.Error("MonitorItemValueTask", err.Error())
|
||||
this.logErr("MonitorItemValueTask", err.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user