增加节点同步状态提示和任务列表

This commit is contained in:
GoEdgeLab
2021-01-17 16:48:00 +08:00
parent 381f83c94c
commit 747cdac7cf
49 changed files with 1959 additions and 580 deletions

View File

@@ -0,0 +1,51 @@
package tasks
import (
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
"github.com/iwind/TeaGo/dbs"
"github.com/iwind/TeaGo/logs"
"time"
)
func init() {
dbs.OnReady(func() {
go NewNodeTaskExtractor().Start()
})
}
// 节点任务
type NodeTaskExtractor struct {
}
func NewNodeTaskExtractor() *NodeTaskExtractor {
return &NodeTaskExtractor{}
}
func (this *NodeTaskExtractor) Start() {
ticker := time.NewTicker(10 * time.Second)
for range ticker.C {
err := this.Loop()
if err != nil {
logs.Println("[TASK][NODE_TASK_EXTRACTOR]" + err.Error())
}
}
}
func (this *NodeTaskExtractor) Loop() error {
ok, err := models.SharedSysLockerDAO.Lock(nil, "node_task_extractor", 10-1) // 假设执行时间为1秒
if err != nil {
return err
}
if !ok {
return nil
}
// 这里不解锁是为了让任务N秒钟之内只运行一次
err = models.SharedNodeTaskDAO.ExtractAllClusterTasks(nil)
if err != nil {
return err
}
return nil
}