mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-30 12:10:25 +08:00
增加节点同步状态提示和任务列表
This commit is contained in:
51
internal/tasks/node_task_extractor.go
Normal file
51
internal/tasks/node_task_extractor.go
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user