mirror of
https://gitee.com/dromara/mayfly-go
synced 2025-11-04 00:10:25 +08:00
!84 fix: 修复数据库备份与恢复问题
* refactor dbScheduler * fix: 按团队名称检索团队 * feat: 创建数据库资源时支持全选数据库 * refactor dbScheduler * fix: 修复数据库备份与恢复问题
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
package entity
|
||||
|
||||
import (
|
||||
"context"
|
||||
"mayfly-go/pkg/runner"
|
||||
"mayfly-go/pkg/utils/timex"
|
||||
"time"
|
||||
)
|
||||
|
||||
var _ DbJob = (*DbRestore)(nil)
|
||||
@@ -12,20 +12,59 @@ var _ DbJob = (*DbRestore)(nil)
|
||||
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 (d *DbRestore) SetRun(fn func(ctx context.Context, job DbJob)) {
|
||||
d.run = func(ctx context.Context) {
|
||||
fn(ctx, d)
|
||||
}
|
||||
func (r *DbRestore) GetDbName() string {
|
||||
return r.DbName
|
||||
}
|
||||
|
||||
func (d *DbRestore) SetRunnable(fn func(job DbJob, next runner.NextFunc) bool) {
|
||||
d.runnable = func(next runner.NextFunc) bool {
|
||||
return fn(d, next)
|
||||
func (r *DbRestore) Schedule() (time.Time, error) {
|
||||
var deadline time.Time
|
||||
if r.IsFinished() || !r.Enabled {
|
||||
return deadline, runner.ErrFinished
|
||||
}
|
||||
switch r.LastStatus {
|
||||
case DbJobSuccess:
|
||||
lastTime := r.LastTime.Time
|
||||
if lastTime.Before(r.StartTime) {
|
||||
lastTime = r.StartTime.Add(-r.Interval)
|
||||
}
|
||||
deadline = lastTime.Add(r.Interval - lastTime.Sub(r.StartTime)%r.Interval)
|
||||
case DbJobFailed:
|
||||
deadline = time.Now().Add(time.Minute)
|
||||
default:
|
||||
deadline = r.StartTime
|
||||
}
|
||||
return deadline, 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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user