fix: 解决应用恢复导致计划任务执行失败的问题 (#3769)

This commit is contained in:
ssongliu
2024-01-31 10:47:21 +00:00
committed by GitHub
parent be53945f0e
commit 08a45e9723
2 changed files with 11 additions and 0 deletions
+7
View File
@@ -20,6 +20,7 @@ type ICronjobRepo interface {
Page(limit, offset int, opts ...DBOption) (int64, []model.Cronjob, error)
Create(cronjob *model.Cronjob) error
WithByJobID(id int) DBOption
WithByDbName(name string) DBOption
WithByDefaultDownload(account string) DBOption
WithByRecordDropID(id int) DBOption
WithByRecordFile(file string) DBOption
@@ -117,6 +118,12 @@ func (c *CronjobRepo) WithByJobID(id int) DBOption {
}
}
func (c *CronjobRepo) WithByDbName(name string) DBOption {
return func(g *gorm.DB) *gorm.DB {
return g.Where("db_name = ?", name)
}
}
func (c *CronjobRepo) WithByDefaultDownload(account string) DBOption {
return func(g *gorm.DB) *gorm.DB {
return g.Where("default_download = ?", account)
+4
View File
@@ -303,6 +303,10 @@ func reCreateDB(dbID uint, database model.Database, oldEnv string) (*model.Datab
Password: oldPassword,
Permission: "%",
})
cronjobs, _ := cronjobRepo.List(cronjobRepo.WithByDbName(fmt.Sprintf("%v", dbID)))
for _, job := range cronjobs {
_ = cronjobRepo.Update(job.ID, map[string]interface{}{"db_name": fmt.Sprintf("%v", createDB.ID)})
}
if err != nil {
return nil, envMap, err
}