Skip to content

Commit ca586bb

Browse files
authored
fix: 快照前停止计划任务执行 (#1888)
1 parent 25ccade commit ca586bb

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

backend/app/service/snapshot.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,9 @@ func (u *SnapshotService) SnapshotCreate(req dto.SnapshotCreate) error {
145145
}
146146
_ = snapshotRepo.Create(&snap)
147147
go func() {
148+
_ = global.Cron.Stop()
148149
defer func() {
150+
global.Cron.Start()
149151
_ = os.RemoveAll(rootDir)
150152
}()
151153
fileOp := files.NewFileOp()
@@ -254,6 +256,10 @@ func (u *SnapshotService) SnapshotRecover(req dto.SnapshotRecover) error {
254256
_ = snapshotRepo.Update(snap.ID, map[string]interface{}{"recover_status": constant.StatusWaiting})
255257
_ = settingRepo.Update("SystemStatus", "Recovering")
256258
go func() {
259+
_ = global.Cron.Stop()
260+
defer func() {
261+
global.Cron.Start()
262+
}()
257263
operation := "recover"
258264
if isReTry {
259265
operation = "re-recover"
@@ -418,6 +424,10 @@ func (u *SnapshotService) SnapshotRollback(req dto.SnapshotRecover) error {
418424
_ = settingRepo.Update("SystemStatus", "Rollbacking")
419425
_ = snapshotRepo.Update(snap.ID, map[string]interface{}{"rollback_status": constant.StatusWaiting})
420426
go func() {
427+
_ = global.Cron.Stop()
428+
defer func() {
429+
global.Cron.Start()
430+
}()
421431
snapJson, err := u.readFromJson(fmt.Sprintf("%s/snapshot.json", rootDir))
422432
if err != nil {
423433
updateRollbackStatus(snap.ID, constant.StatusFailed, fmt.Sprintf("decompress file failed, err: %v", err))

0 commit comments

Comments
 (0)