mirror of
https://gitee.com/dromara/mayfly-go
synced 2026-04-24 05:05:20 +08:00
refactor: 后端包结构重构、去除无用的文件
This commit is contained in:
27
server/internal/devops/infrastructure/scheudler/mytask.go
Normal file
27
server/internal/devops/infrastructure/scheudler/mytask.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package scheduler
|
||||
|
||||
func init() {
|
||||
SaveMachineMonitor()
|
||||
}
|
||||
|
||||
func SaveMachineMonitor() {
|
||||
AddFun("@every 60s", func() {
|
||||
// for _, m := range models.GetNeedMonitorMachine() {
|
||||
// m := m
|
||||
// go func() {
|
||||
// cli, err := machine.GetCli(uint64(utils.GetInt4Map(m, "id")))
|
||||
// if err != nil {
|
||||
// mlog.Log.Error("获取客户端失败:", err.Error())
|
||||
// return
|
||||
// }
|
||||
// mm := cli.GetMonitorInfo()
|
||||
// if mm != nil {
|
||||
// err := model.Insert(mm)
|
||||
// if err != nil {
|
||||
// mlog.Log.Error("保存机器监控信息失败: ", err.Error())
|
||||
// }
|
||||
// }
|
||||
// }()
|
||||
// }
|
||||
})
|
||||
}
|
||||
33
server/internal/devops/infrastructure/scheudler/scheduler.go
Normal file
33
server/internal/devops/infrastructure/scheudler/scheduler.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package scheduler
|
||||
|
||||
import (
|
||||
"mayfly-go/pkg/biz"
|
||||
|
||||
"github.com/robfig/cron/v3"
|
||||
)
|
||||
|
||||
var cronService = cron.New()
|
||||
|
||||
func Start() {
|
||||
cronService.Start()
|
||||
}
|
||||
|
||||
func Stop() {
|
||||
cronService.Stop()
|
||||
}
|
||||
|
||||
func Remove(id cron.EntryID) {
|
||||
cronService.Remove(id)
|
||||
}
|
||||
|
||||
func GetCron() *cron.Cron {
|
||||
return cronService
|
||||
}
|
||||
|
||||
func AddFun(spec string, cmd func()) cron.EntryID {
|
||||
id, err := cronService.AddFunc(spec, cmd)
|
||||
if err != nil {
|
||||
panic(biz.NewBizErr("添加任务失败:" + err.Error()))
|
||||
}
|
||||
return id
|
||||
}
|
||||
Reference in New Issue
Block a user