2021-01-18 20:59:04 -05:00
|
|
|
package model
|
|
|
|
|
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
2022-03-18 11:13:22 -04:00
|
|
|
"github.com/naiba/nezha/pkg/utils"
|
2021-01-18 20:59:04 -05:00
|
|
|
"github.com/robfig/cron/v3"
|
|
|
|
"gorm.io/gorm"
|
|
|
|
)
|
|
|
|
|
2021-06-21 09:30:42 -04:00
|
|
|
const (
|
|
|
|
CronCoverIgnoreAll = iota
|
|
|
|
CronCoverAll
|
|
|
|
)
|
|
|
|
|
2021-01-18 20:59:04 -05:00
|
|
|
type Cron struct {
|
|
|
|
Common
|
2022-04-14 09:06:42 -04:00
|
|
|
Name string
|
|
|
|
Scheduler string //分钟 小时 天 月 星期
|
|
|
|
Command string
|
|
|
|
Servers []uint64 `gorm:"-"`
|
|
|
|
PushSuccessful bool // 推送成功的通知
|
|
|
|
NotificationTag string // 指定通知方式的分组
|
|
|
|
LastExecutedAt time.Time // 最后一次执行时间
|
|
|
|
LastResult bool // 最后一次执行结果
|
|
|
|
Cover uint8 // 计划任务覆盖范围 (0:仅覆盖特定服务器 1:仅忽略特定服务器)
|
2021-01-18 20:59:04 -05:00
|
|
|
|
2022-04-10 08:28:22 -04:00
|
|
|
CronJobID cron.EntryID `gorm:"-"`
|
2021-01-18 20:59:04 -05:00
|
|
|
ServersRaw string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Cron) AfterFind(tx *gorm.DB) error {
|
2022-03-18 11:13:22 -04:00
|
|
|
return utils.Json.Unmarshal([]byte(c.ServersRaw), &c.Servers)
|
2021-01-18 20:59:04 -05:00
|
|
|
}
|