mirror of
https://github.com/Buriburizaem0n/nezha_domains.git
synced 2026-02-04 12:40:07 +00:00
🔊 v0.3.0 计划任务(定期备份等场景)
This commit is contained in:
27
model/cron.go
Normal file
27
model/cron.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"time"
|
||||
|
||||
"github.com/robfig/cron/v3"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type Cron struct {
|
||||
Common
|
||||
Name string
|
||||
Scheduler string //分钟 小时 天 月 星期
|
||||
Command string
|
||||
Servers []uint64 `gorm:"-"`
|
||||
PushSuccessful bool // 推送成功的通知
|
||||
LastExecutedAt time.Time // 最后一次执行时间
|
||||
LastResult bool // 最后一次执行结果
|
||||
|
||||
CronID cron.EntryID `gorn:"-"`
|
||||
ServersRaw string
|
||||
}
|
||||
|
||||
func (c *Cron) AfterFind(tx *gorm.DB) error {
|
||||
return json.Unmarshal([]byte(c.ServersRaw), &c.Servers)
|
||||
}
|
||||
@@ -6,9 +6,10 @@ import (
|
||||
|
||||
const (
|
||||
_ = iota
|
||||
MonitorTypeHTTPGET
|
||||
MonitorTypeICMPPing
|
||||
MonitorTypeTCPPing
|
||||
TaskTypeHTTPGET
|
||||
TaskTypeICMPPing
|
||||
TaskTypeTCPPing
|
||||
TaskTypeCommand
|
||||
)
|
||||
|
||||
type Monitor struct {
|
||||
|
||||
@@ -5,7 +5,8 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/google/go-github/github"
|
||||
"github.com/naiba/com"
|
||||
|
||||
"github.com/naiba/nezha/pkg/utils"
|
||||
)
|
||||
|
||||
type User struct {
|
||||
@@ -44,6 +45,6 @@ func NewUserFromGitHub(gu *github.User) User {
|
||||
}
|
||||
|
||||
func (u *User) IssueNewToken() {
|
||||
u.Token = com.MD5(fmt.Sprintf("%d%d%s", time.Now().UnixNano(), u.ID, u.Login))
|
||||
u.Token = utils.MD5(fmt.Sprintf("%d%d%s", time.Now().UnixNano(), u.ID, u.Login))
|
||||
u.TokenExpired = time.Now().AddDate(0, 2, 0)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user