Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions agent/app/dto/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ type CommonRecover struct {
Secret string `json:"secret"`
TaskID string `json:"taskID"`
BackupRecordID uint `json:"backupRecordID"`
Timeout int `json:"timeout"`
}

type RecordSearch struct {
Expand Down
11 changes: 10 additions & 1 deletion agent/app/service/backup_mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
return nil
}

func handleMysqlRecover(req dto.CommonRecover, parentTask *task.Task, isRollback bool) error {

Check failure on line 105 in agent/app/service/backup_mysql.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this method to reduce its Cognitive Complexity from 35 to the 15 allowed.

See more on https://sonarcloud.io/project/issues?id=1Panel-dev_1Panel&issues=AZshLQjaRfr_SFIFVEY2&open=AZshLQjaRfr_SFIFVEY2&pullRequest=11338
var (
err error
itemTask *task.Task
Expand Down Expand Up @@ -193,7 +193,16 @@
return recoverDatabase(parentTask)
}

itemTask.AddSubTaskWithOps(i18n.GetMsgByKey("TaskRecover"), recoverDatabase, nil, 0, 3*time.Hour)
var timeout time.Duration
switch req.Timeout {
case -1:
timeout = 0
case 0:
timeout = 3 * time.Hour
default:
timeout = time.Duration(req.Timeout) * time.Second
}
itemTask.AddSubTaskWithOps(i18n.GetMsgByKey("TaskRecover"), recoverDatabase, nil, 0, timeout)
go func() {
_ = itemTask.Execute()
}()
Expand Down
11 changes: 10 additions & 1 deletion agent/app/service/backup_postgresql.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
return nil
}

func handlePostgresqlRecover(req dto.CommonRecover, parentTask *task.Task, isRollback bool) error {

Check failure on line 99 in agent/app/service/backup_postgresql.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this method to reduce its Cognitive Complexity from 33 to the 15 allowed.

See more on https://sonarcloud.io/project/issues?id=1Panel-dev_1Panel&issues=AZshLQeiRfr_SFIFVEY1&open=AZshLQeiRfr_SFIFVEY1&pullRequest=11338
var (
err error
itemTask *task.Task
Expand Down Expand Up @@ -187,7 +187,16 @@
return recoverDatabase(parentTask)
}

itemTask.AddSubTaskWithOps(i18n.GetMsgByKey("TaskRecover"), recoverDatabase, nil, 0, 3*time.Hour)
var timeout time.Duration
switch req.Timeout {
case -1:
timeout = 0
case 0:
timeout = 3 * time.Hour
default:
timeout = time.Duration(req.Timeout) * time.Second
}
itemTask.AddSubTaskWithOps(i18n.GetMsgByKey("TaskRecover"), recoverDatabase, nil, 0, timeout)
go func() {
_ = itemTask.Execute()
}()
Expand Down
3 changes: 3 additions & 0 deletions agent/app/task/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@
t.SubTasks = append(t.SubTasks, subTask)
}

func (s *SubTask) Execute() error {

Check failure on line 217 in agent/app/task/task.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this method to reduce its Cognitive Complexity from 17 to the 15 allowed.

See more on https://sonarcloud.io/project/issues?id=1Panel-dev_1Panel&issues=AZshLQjjRfr_SFIFVEY3&open=AZshLQjjRfr_SFIFVEY3&pullRequest=11338
defer delete(global.TaskCtxMap, s.RootTask.TaskID)
subTaskName := s.Name
if s.Name == "" {
Expand All @@ -226,6 +226,9 @@
s.RootTask.Log(i18n.GetWithName("TaskRetry", strconv.Itoa(i)))
}
ctx, cancel := context.WithTimeout(context.Background(), s.Timeout)
if s.Timeout == 0 {
ctx, cancel = context.WithCancel(context.Background())

Check failure on line 230 in agent/app/task/task.go

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Defer the cancel function 'cancel' after this context creation to prevent resource leaks.

See more on https://sonarcloud.io/project/issues?id=1Panel-dev_1Panel&issues=AZshLQjjRfr_SFIFVEY4&open=AZshLQjjRfr_SFIFVEY4&pullRequest=11338
}
defer cancel()

done := make(chan error)
Expand Down
21 changes: 20 additions & 1 deletion frontend/src/components/backup/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,22 @@
<el-form-item :label="$t('setting.compressPassword')">
<el-input v-model="secret" :placeholder="$t('setting.backupRecoverMessage')" />
</el-form-item>
<el-form-item
v-if="!isBackup && type !== 'app' && type !== 'website'"
:label="$t('cronjob.timeout')"
prop="timeoutItem"
>
<el-input type="number" class="selectClass" v-model.number="timeoutItem">
<template #append>
<el-select v-model="timeoutUnit" style="width: 80px">
<el-option :label="$t('commons.units.second')" value="s" />
<el-option :label="$t('commons.units.minute')" value="m" />
<el-option :label="$t('commons.units.hour')" value="h" />
</el-select>
</template>
</el-input>
<span class="input-help">{{ $t('database.recoverTimeoutHelper') }}</span>
</el-form-item>
<el-form-item v-if="isBackup" :label="$t('commons.table.description')">
<el-input type="textarea" :autosize="{ minRows: 2, maxRows: 5 }" v-model="description" />
</el-form-item>
Expand All @@ -133,7 +149,7 @@

<script lang="ts" setup>
import { reactive, ref } from 'vue';
import { computeSize, dateFormat, downloadFile, newUUID } from '@/utils/util';
import { computeSize, dateFormat, downloadFile, newUUID, transferTimeToSecond } from '@/utils/util';
import {
getLocalBackupDir,
handleBackup,
Expand Down Expand Up @@ -182,6 +198,8 @@ const backupPath = ref();
const status = ref();
const secret = ref();
const description = ref();
const timeoutItem = ref(30);
const timeoutUnit = ref('m');

const open = ref();
const isBackup = ref();
Expand Down Expand Up @@ -314,6 +332,7 @@ const recover = async (row?: any) => {
secret: secret.value,
taskID: taskID,
backupRecordID: row.id,
timeout: timeoutItem.value === -1 ? -1 : transferTimeToSecond(timeoutItem.value + timeoutUnit.value),
};
loading.value = true;
await handleRecover(params)
Expand Down
21 changes: 20 additions & 1 deletion frontend/src/components/upload/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,22 @@
<el-form-item :label="$t('setting.compressPassword')">
<el-input v-model="secret" :placeholder="$t('setting.backupRecoverMessage')" />
</el-form-item>
<el-form-item
v-if="type !== 'app' && type !== 'website'"
:label="$t('cronjob.timeout')"
prop="timeoutItem"
>
<el-input type="number" class="selectClass" v-model.number="timeoutItem">
<template #append>
<el-select v-model="timeoutUnit" style="width: 80px">
<el-option :label="$t('commons.units.second')" value="s" />
<el-option :label="$t('commons.units.minute')" value="m" />
<el-option :label="$t('commons.units.hour')" value="h" />
</el-select>
</template>
</el-input>
<span class="input-help">{{ $t('database.recoverTimeoutHelper') }}</span>
</el-form-item>
</el-form>
<template #footer>
<span class="dialog-footer">
Expand All @@ -115,7 +131,7 @@

<script lang="ts" setup>
import { reactive, ref } from 'vue';
import { computeSize, newUUID } from '@/utils/util';
import { computeSize, newUUID, transferTimeToSecond } from '@/utils/util';
import i18n from '@/lang';
import { UploadFile, UploadFiles, UploadInstance, UploadProps, UploadRawFile, genFileId } from 'element-plus';
import { File } from '@/api/interface/file';
Expand Down Expand Up @@ -152,6 +168,8 @@ const name = ref();
const detailName = ref();
const remark = ref();
const secret = ref();
const timeoutItem = ref(30);
const timeoutUnit = ref('m');
const taskLogRef = ref();

const recoverDialog = ref();
Expand Down Expand Up @@ -261,6 +279,7 @@ const onHandleRecover = async () => {
file: baseDir.value + currentRow.value.name,
secret: secret.value,
taskID: newUUID(),
timeout: timeoutItem.value === -1 ? -1 : transferTimeToSecond(timeoutItem.value + timeoutUnit.value),
};
loading.value = true;
await handleRecoverByUpload(params)
Expand Down
1 change: 1 addition & 0 deletions frontend/src/lang/modules/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,7 @@ const message = {
changeConnHelper: 'This operation will modify the current database {0}. Do you want to continue?',
changePasswordHelper:
'The database has been associated with an application. Changing the password will change the database password of the application at the same time. The change takes effect after the application restarts.',
recoverTimeoutHelper: '-1 means no timeout limit',

confChange: 'Configuration',
confNotFound:
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/lang/modules/es-es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,8 @@ const message = {
changeConnHelper: 'Esta operación modificará la base de datos actual {0}. ¿Desea continuar?',
changePasswordHelper:
'La base de datos ha sido asociada a una aplicación. Cambiar la contraseña también cambiará la contraseña de la base de datos en la aplicación. El cambio se aplica después de reiniciar la aplicación.',
recoverTimeoutHelper: '-1 significa sin límite de tiempo de espera',

confChange: 'Configuración',
confNotFound:
'No se pudo encontrar el archivo de configuración. Por favor actualice la aplicación a la última versión en la tienda y vuelva a intentarlo.',
Expand Down
1 change: 1 addition & 0 deletions frontend/src/lang/modules/ja.ts
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,7 @@ const message = {
changeConnHelper: 'この操作は現在のデータベース {0} を変更します。続行しますか?',
changePasswordHelper:
'データベースはアプリケーションに関連付けられています。パスワードを変更すると、アプリケーションのデータベースパスワードが同時に変更されます。アプリケーションが再起動した後、変更は有効になります。',
recoverTimeoutHelper: '-1 はタイムアウト制限なしを意味します',

confChange: '構成',
confNotFound:
Expand Down
1 change: 1 addition & 0 deletions frontend/src/lang/modules/ko.ts
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,7 @@ const message = {
changeConnHelper: '이 작업은 현재 데이터베이스 {0}을(를) 수정합니다. 계속하시겠습니까?',
changePasswordHelper:
'데이터베이스가 애플리케이션과 연결되어 있습니다. 비밀번호를 변경하면 애플리케이션의 데이터베이스 비밀번호도 변경됩니다. 변경 사항은 애플리케이션이 재시작된 후에 적용됩니다.',
recoverTimeoutHelper: '-1은 제한 시간 제한 없음을 의미합니다',
confChange: '설정',
confNotFound:
'설정 파일을 찾을 수 없습니다. 앱 스토어에서 애플리케이션을 최신 버전으로 업그레이드하고 다시 시도해주세요!',
Expand Down
1 change: 1 addition & 0 deletions frontend/src/lang/modules/ms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,7 @@ const message = {
changeConnHelper: 'Operasi ini akan mengubah pangkalan data semasa {0}. Adakah anda ingin meneruskan?',
changePasswordHelper:
'Pangkalan data telah dikaitkan dengan aplikasi. Menukar kata laluan akan menukar kata laluan pangkalan data aplikasi pada masa yang sama. Perubahan ini akan berkuat kuasa selepas aplikasi dimulakan semula.',
recoverTimeoutHelper: '-1 bermaksud tiada had masa tamat',

confChange: 'Konfigurasi',
confNotFound:
Expand Down
1 change: 1 addition & 0 deletions frontend/src/lang/modules/pt-br.ts
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,7 @@ const message = {
changeConnHelper: 'Esta operação modificará o banco de dados atual {0}. Deseja continuar?',
changePasswordHelper:
'O banco de dados está associado a um aplicativo. Alterar a senha alterará a senha do banco de dados do aplicativo ao mesmo tempo. A mudança surtirá efeito após a reinicialização do aplicativo.',
recoverTimeoutHelper: '-1 significa sem limite de tempo limite',

confChange: 'Configuração',
confNotFound:
Expand Down
1 change: 1 addition & 0 deletions frontend/src/lang/modules/ru.ts
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,7 @@ const message = {
changePassword: 'Пароль',
changePasswordHelper:
'База данных была связана с приложением. Изменение пароля изменит пароль базы данных приложения одновременно. Изменение вступит в силу после перезапуска приложения.',
recoverTimeoutHelper: '-1 означает отсутствие ограничения по времени ожидания',

confChange: 'Конфигурация',
confNotFound:
Expand Down
1 change: 1 addition & 0 deletions frontend/src/lang/modules/tr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,7 @@ const message = {
changeConnHelper: 'Bu işlem mevcut {0} veritabanını değiştirecek. Devam etmek istiyor musunuz?',
changePasswordHelper:
'Veritabanı bir uygulamayla ilişkilendirildi. Şifre değiştirmek aynı zamanda uygulamanın veritabanı şifresini de değiştirecek. Değişiklik uygulama yeniden başlatıldıktan sonra etkili olur.',
recoverTimeoutHelper: '-1, zaman aşımı sınırı olmadığı anlamına gelir',

confChange: 'Yapılandırma',
confNotFound:
Expand Down
1 change: 1 addition & 0 deletions frontend/src/lang/modules/zh-Hant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,7 @@ const message = {
changePassword: '改密',
changeConnHelper: '此操作將修改目前資料庫 {0},是否繼續?',
changePasswordHelper: '目前資料庫已經關聯應用,修改密碼將同步修改應用中資料庫密碼,修改後重啟生效。',
recoverTimeoutHelper: '-1 表示不限制超時時間',

portHelper: '該埠為容器對外暴露埠,修改需要單獨儲存並且重啟容器!',

Expand Down
1 change: 1 addition & 0 deletions frontend/src/lang/modules/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,7 @@ const message = {
changePassword: '改密',
changeConnHelper: '此操作将修改当前数据库 {0},是否继续?',
changePasswordHelper: '当前数据库已经关联应用,修改密码将同步修改应用中数据库密码,修改后重启生效。',
recoverTimeoutHelper: '为 -1 表示不限制超时时间',

portHelper: '该端口为容器对外暴露端口,修改需要单独保存并且重启容器!',

Expand Down
Loading