mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-15 00:40:26 +08:00
增加健康检查定时任务/健康检查可以发送消息
This commit is contained in:
40
internal/tasks/node_log_cleaner_task.go
Normal file
40
internal/tasks/node_log_cleaner_task.go
Normal file
@@ -0,0 +1,40 @@
|
||||
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 NewNodeLogCleanerTask().Start()
|
||||
})
|
||||
}
|
||||
|
||||
// 清理节点日志的工具
|
||||
type NodeLogCleanerTask struct {
|
||||
duration time.Duration
|
||||
}
|
||||
|
||||
func NewNodeLogCleanerTask() *NodeLogCleanerTask {
|
||||
return &NodeLogCleanerTask{
|
||||
duration: 24 * time.Hour,
|
||||
}
|
||||
}
|
||||
|
||||
func (this *NodeLogCleanerTask) Start() {
|
||||
ticker := time.NewTicker(this.duration)
|
||||
for range ticker.C {
|
||||
err := this.loop()
|
||||
if err != nil {
|
||||
logs.Println("[TASK]" + err.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (this *NodeLogCleanerTask) loop() error {
|
||||
// TODO 30天这个数值改成可以设置
|
||||
return models.SharedNodeLogDAO.DeleteExpiredLogs(30)
|
||||
}
|
||||
Reference in New Issue
Block a user