增加健康检查定时任务/健康检查可以发送消息

This commit is contained in:
刘祥超
2020-10-20 16:45:03 +08:00
parent fd8ee5b926
commit 5c407f5d92
17 changed files with 555 additions and 20 deletions

View File

@@ -0,0 +1,41 @@
package tasks
import (
"github.com/TeaOSLab/EdgeAPI/internal/db/models"
"github.com/TeaOSLab/EdgeAPI/internal/utils"
"github.com/iwind/TeaGo/dbs"
"github.com/iwind/TeaGo/logs"
"time"
)
func init() {
dbs.OnReady(func() {
go NewMessageTask().Run()
})
}
// 消息相关任务
type MessageTask struct {
}
// 获取新对象
func NewMessageTask() *MessageTask {
return &MessageTask{}
}
// 运行
func (this *MessageTask) Run() {
ticker := utils.NewTicker(24 * time.Hour)
for ticker.Wait() {
err := this.loop()
if err != nil {
logs.Println("[TASK][MESSAGE]" + err.Error())
}
}
}
// 单次运行
func (this *MessageTask) loop() error {
dayTime := time.Now().AddDate(0, 0, -30) // TODO 这个30天应该可以在界面上设置
return models.NewMessageDAO().DeleteMessagesBeforeDay(dayTime)
}