mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-18 11:50:26 +08:00
实现节点运行日志上传
This commit is contained in:
36
internal/tasks/node_log_cleaner.go
Normal file
36
internal/tasks/node_log_cleaner.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package tasks
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
|
||||
"github.com/iwind/TeaGo/logs"
|
||||
"time"
|
||||
)
|
||||
|
||||
func init() {
|
||||
go NewNodeLogCleaner().Start()
|
||||
}
|
||||
|
||||
type NodeLogCleaner struct {
|
||||
duration time.Duration
|
||||
}
|
||||
|
||||
func NewNodeLogCleaner() *NodeLogCleaner {
|
||||
return &NodeLogCleaner{
|
||||
duration: 24 * time.Hour,
|
||||
}
|
||||
}
|
||||
|
||||
func (this *NodeLogCleaner) Start() {
|
||||
ticker := time.NewTicker(this.duration)
|
||||
for range ticker.C {
|
||||
err := this.loop()
|
||||
if err != nil {
|
||||
logs.Println("[TASK]" + err.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (this *NodeLogCleaner) loop() error {
|
||||
// TODO 30天这个数值改成可以设置
|
||||
return models.SharedNodeLogDAO.DeleteExpiredLogs(30)
|
||||
}
|
||||
Reference in New Issue
Block a user