Files
mayfly-go/server/internal/db/domain/entity/db_restore.go
kanzihuang b017b902f8 !85 fix: 修复 BINLOG同步任务加载问题
* Merge branch 'dev' of gitee.com:dromara/mayfly-go into feat-db-bak
* fix: 修复 BINLOG 同步任务加载问题
2024-01-19 00:40:44 +00:00

66 lines
1.7 KiB
Go

package entity
import (
"mayfly-go/pkg/runner"
"mayfly-go/pkg/utils/timex"
"time"
)
var _ DbJob = (*DbRestore)(nil)
// DbRestore 数据库恢复任务
type DbRestore struct {
*DbJobBaseImpl
DbName string // 数据库名称
Enabled bool // 是否启用
StartTime time.Time // 开始时间
Interval time.Duration // 间隔时间
Repeated bool // 是否重复执行
PointInTime timex.NullTime `json:"pointInTime"` // 指定数据库恢复的时间点
DbBackupId uint64 `json:"dbBackupId"` // 用于恢复的数据库恢复任务ID
DbBackupHistoryId uint64 `json:"dbBackupHistoryId"` // 用于恢复的数据库恢复历史ID
DbBackupHistoryName string `json:"dbBackupHistoryName"` // 数据库恢复历史名称
}
func (r *DbRestore) GetDbName() string {
return r.DbName
}
func (r *DbRestore) Schedule() (time.Time, error) {
if !r.Enabled {
return time.Time{}, runner.ErrJobDisabled
}
switch r.LastStatus {
case DbJobSuccess, DbJobFailed:
return time.Time{}, runner.ErrJobFinished
default:
if time.Now().Sub(r.StartTime) > time.Hour {
return time.Time{}, runner.ErrJobTimeout
}
return r.StartTime, nil
}
}
func (r *DbRestore) IsEnabled() bool {
return r.Enabled
}
func (r *DbRestore) SetEnabled(enabled bool) {
r.Enabled = enabled
}
func (r *DbRestore) IsFinished() bool {
return !r.Repeated && r.LastStatus == DbJobSuccess
}
func (r *DbRestore) Update(job runner.Job) {
restore := job.(*DbRestore)
r.StartTime = restore.StartTime
r.Interval = restore.Interval
}
func (r *DbRestore) GetInterval() time.Duration {
return r.Interval
}