feat: 实现数据库备份和恢复并发调度 (#84)

This commit is contained in:
kanzihuang
2024-01-11 11:35:51 +08:00
committed by GitHub
parent 3857d674ba
commit bbec3eca0d
40 changed files with 1373 additions and 843 deletions

View File

@@ -1,36 +1,31 @@
package entity
import (
"context"
"mayfly-go/pkg/runner"
"mayfly-go/pkg/utils/timex"
)
var _ DbTask = (*DbRestore)(nil)
var _ DbJob = (*DbRestore)(nil)
// DbRestore 数据库恢复任务
type DbRestore struct {
*DbTaskBase
*DbJobBaseImpl
DbName string `json:"dbName"` // 数据库名
PointInTime timex.NullTime `json:"pointInTime"` // 指定数据库恢复的时间点
DbBackupId uint64 `json:"dbBackupId"` // 用于恢复的数据库恢复任务ID
DbBackupHistoryId uint64 `json:"dbBackupHistoryId"` // 用于恢复的数据库恢复历史ID
DbBackupHistoryName string `json:"dbBackupHistoryName"` // 数据库恢复历史名称
DbInstanceId uint64 `json:"dbInstanceId"` // 数据库实例ID
}
func (*DbRestore) MessageWithStatus(status TaskStatus) string {
var result string
switch status {
case TaskDelay:
result = "等待恢复数据库"
case TaskReady:
result = "准备恢复数据库"
case TaskReserved:
result = "数据库恢复中"
case TaskSuccess:
result = "数据库恢复成功"
case TaskFailed:
result = "数据库恢复失败"
func (d *DbRestore) SetRun(fn func(ctx context.Context, job DbJob)) {
d.run = func(ctx context.Context) {
fn(ctx, d)
}
}
func (d *DbRestore) SetRunnable(fn func(job DbJob, next runner.NextFunc) bool) {
d.runnable = func(next runner.NextFunc) bool {
return fn(d, next)
}
return result
}