Skip to content

Commit 8f329f2

Browse files
committed
feat: Database restore supports timeout settings
1 parent 191396c commit 8f329f2

File tree

4 files changed

+24
-2
lines changed

4 files changed

+24
-2
lines changed

agent/app/dto/backup.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ type CommonRecover struct {
8383
Secret string `json:"secret"`
8484
TaskID string `json:"taskID"`
8585
BackupRecordID uint `json:"backupRecordID"`
86+
Timeout int `json:"timeout"`
8687
}
8788

8889
type RecordSearch struct {

agent/app/service/backup_mysql.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,16 @@ func handleMysqlRecover(req dto.CommonRecover, parentTask *task.Task, isRollback
193193
return recoverDatabase(parentTask)
194194
}
195195

196-
itemTask.AddSubTaskWithOps(i18n.GetMsgByKey("TaskRecover"), recoverDatabase, nil, 0, 3*time.Hour)
196+
var timeout time.Duration
197+
switch req.Timeout {
198+
case -1:
199+
timeout = 0
200+
case 0:
201+
timeout = 3 * time.Hour
202+
default:
203+
timeout = time.Duration(req.Timeout) * time.Second
204+
}
205+
itemTask.AddSubTaskWithOps(i18n.GetMsgByKey("TaskRecover"), recoverDatabase, nil, 0, timeout)
197206
go func() {
198207
_ = itemTask.Execute()
199208
}()

agent/app/service/backup_postgresql.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,16 @@ func handlePostgresqlRecover(req dto.CommonRecover, parentTask *task.Task, isRol
187187
return recoverDatabase(parentTask)
188188
}
189189

190-
itemTask.AddSubTaskWithOps(i18n.GetMsgByKey("TaskRecover"), recoverDatabase, nil, 0, 3*time.Hour)
190+
var timeout time.Duration
191+
switch req.Timeout {
192+
case -1:
193+
timeout = 0
194+
case 0:
195+
timeout = 3 * time.Hour
196+
default:
197+
timeout = time.Duration(req.Timeout) * time.Second
198+
}
199+
itemTask.AddSubTaskWithOps(i18n.GetMsgByKey("TaskRecover"), recoverDatabase, nil, 0, timeout)
191200
go func() {
192201
_ = itemTask.Execute()
193202
}()

agent/app/task/task.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,9 @@ func (s *SubTask) Execute() error {
226226
s.RootTask.Log(i18n.GetWithName("TaskRetry", strconv.Itoa(i)))
227227
}
228228
ctx, cancel := context.WithTimeout(context.Background(), s.Timeout)
229+
if s.Timeout == 0 {
230+
ctx, cancel = context.WithCancel(context.Background())
231+
}
229232
defer cancel()
230233

231234
done := make(chan error)

0 commit comments

Comments
 (0)