fix: 依赖注入支持私有变量

This commit is contained in:
wanli
2024-01-23 16:29:41 +08:00
parent 3fc86f0fae
commit 070d4ea104
10 changed files with 107 additions and 112 deletions

View File

@@ -8,62 +8,62 @@ import (
)
type DbRestoreApp struct {
DbApp Db `inject:"DbApp"`
Scheduler *dbScheduler `inject:"DbScheduler"`
InstanceRepo repository.Instance `inject:"DbInstanceRepo"`
BackupHistoryRepo repository.DbBackupHistory `inject:"DbBackupHistoryRepo"`
RestoreRepo repository.DbRestore `inject:"DbRestoreRepo"`
RestoreHistoryRepo repository.DbRestoreHistory `inject:"DbRestoreHistoryRepo"`
BinlogHistoryRepo repository.DbBinlogHistory `inject:"DbBinlogHistoryRepo"`
dbApp Db `inject:"DbApp"`
scheduler *dbScheduler `inject:"DbScheduler"`
instanceRepo repository.Instance `inject:"DbInstanceRepo"`
backupHistoryRepo repository.DbBackupHistory `inject:"DbBackupHistoryRepo"`
restoreRepo repository.DbRestore `inject:"DbRestoreRepo"`
restoreHistoryRepo repository.DbRestoreHistory `inject:"DbRestoreHistoryRepo"`
binlogHistoryRepo repository.DbBinlogHistory `inject:"DbBinlogHistoryRepo"`
}
func (app *DbRestoreApp) Init() error {
var jobs []*entity.DbRestore
if err := app.RestoreRepo.ListToDo(&jobs); err != nil {
if err := app.restoreRepo.ListToDo(&jobs); err != nil {
return err
}
if err := app.Scheduler.AddJob(context.Background(), false, entity.DbJobTypeRestore, jobs); err != nil {
if err := app.scheduler.AddJob(context.Background(), false, entity.DbJobTypeRestore, jobs); err != nil {
return err
}
return nil
}
func (app *DbRestoreApp) Close() {
app.Scheduler.Close()
app.scheduler.Close()
}
func (app *DbRestoreApp) Create(ctx context.Context, job *entity.DbRestore) error {
return app.Scheduler.AddJob(ctx, true /* 保存到数据库 */, entity.DbJobTypeRestore, job)
return app.scheduler.AddJob(ctx, true /* 保存到数据库 */, entity.DbJobTypeRestore, job)
}
func (app *DbRestoreApp) Update(ctx context.Context, job *entity.DbRestore) error {
return app.Scheduler.UpdateJob(ctx, job)
return app.scheduler.UpdateJob(ctx, job)
}
func (app *DbRestoreApp) Delete(ctx context.Context, jobId uint64) error {
// todo: 删除数据库恢复历史文件
return app.Scheduler.RemoveJob(ctx, entity.DbJobTypeRestore, jobId)
return app.scheduler.RemoveJob(ctx, entity.DbJobTypeRestore, jobId)
}
func (app *DbRestoreApp) Enable(ctx context.Context, jobId uint64) error {
return app.Scheduler.EnableJob(ctx, entity.DbJobTypeRestore, jobId)
return app.scheduler.EnableJob(ctx, entity.DbJobTypeRestore, jobId)
}
func (app *DbRestoreApp) Disable(ctx context.Context, jobId uint64) error {
return app.Scheduler.DisableJob(ctx, entity.DbJobTypeRestore, jobId)
return app.scheduler.DisableJob(ctx, entity.DbJobTypeRestore, jobId)
}
// GetPageList 分页获取数据库恢复任务
func (app *DbRestoreApp) GetPageList(condition *entity.DbJobQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error) {
return app.RestoreRepo.GetPageList(condition, pageParam, toEntity, orderBy...)
return app.restoreRepo.GetPageList(condition, pageParam, toEntity, orderBy...)
}
// GetDbNamesWithoutRestore 获取未配置定时恢复的数据库名称
func (app *DbRestoreApp) GetDbNamesWithoutRestore(instanceId uint64, dbNames []string) ([]string, error) {
return app.RestoreRepo.GetDbNamesWithoutRestore(instanceId, dbNames)
return app.restoreRepo.GetDbNamesWithoutRestore(instanceId, dbNames)
}
// GetHistoryPageList 分页获取数据库备份历史
func (app *DbRestoreApp) GetHistoryPageList(condition *entity.DbRestoreHistoryQuery, pageParam *model.PageParam, toEntity any, orderBy ...string) (*model.PageResult[any], error) {
return app.RestoreHistoryRepo.GetDbRestoreHistories(condition, pageParam, toEntity, orderBy...)
return app.restoreHistoryRepo.GetDbRestoreHistories(condition, pageParam, toEntity, orderBy...)
}