Browse Source

feat: 优化计划任务脚本执行错误处理 (#2635)

pull/2637/head
ssongliu 1 year ago committed by GitHub
parent
commit
8cbbef1ac0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      backend/constant/errs.go
  2. 5
      backend/i18n/lang/en.yaml
  3. 5
      backend/i18n/lang/zh-Hant.yaml
  4. 3
      backend/i18n/lang/zh.yaml
  5. 5
      backend/utils/cmd/cmd.go
  6. 26
      backend/utils/encrypt/encrypt_test.go
  7. 2
      frontend/src/views/cronjob/index.vue

5
backend/constant/errs.go

@ -135,3 +135,8 @@ var (
var (
ErrFirewall = "ErrFirewall"
)
// cronjob
var (
ErrBashExecute = "ErrBashExecute"
)

5
backend/i18n/lang/en.yaml

@ -128,4 +128,7 @@ ErrConfigAlreadyExist: "A configuration file with the same name already exists"
ErrUserFindErr: "Failed to find user {{ .name }} {{ .err }}"
#ssh
ErrFirewall: "No firewalld or ufw service is detected. Please check and try again!"
ErrFirewall: "No firewalld or ufw service is detected. Please check and try again!"
#cronjob
ErrBashExecute: "Script execution error, please check stderr-related information in the task output text field."

5
backend/i18n/lang/zh-Hant.yaml

@ -128,4 +128,7 @@ ErrConfigAlreadyExist: "已存在同名配置文件"
ErrUserFindErr: "用戶 {{ .name }} 查找失敗 {{ .err }}"
#ssh
ErrFirewall: "當前未檢測到系統 firewalld 或 ufw 服務,請檢查後重試!"
ErrFirewall: "當前未檢測到系統 firewalld 或 ufw 服務,請檢查後重試!"
#cronjob
ErrBashExecute: "腳本執行錯誤,請在任務輸出文本區域中查看 stderr 相關信息。"

3
backend/i18n/lang/zh.yaml

@ -129,3 +129,6 @@ ErrUserFindErr: "用户 {{ .name }} 查找失败 {{ .err }}"
#ssh
ErrFirewall: "当前未检测到系统 firewalld 或 ufw 服务,请检查后重试!"
#cronjob
ErrBashExecute: "脚本执行错误,请在任务输出文本域中查看 stderr 相关信息。"

5
backend/utils/cmd/cmd.go

@ -88,11 +88,12 @@ func ExecCronjobWithTimeOut(cmdStr string, workdir string, timeout time.Duration
errMsg := ""
if len(stderr.String()) != 0 {
errMsg = fmt.Sprintf("stderr:\n %s", stderr.String())
errMsg = fmt.Sprintf("stderr:\n%s", stderr.String())
err = buserr.New(constant.ErrBashExecute)
}
if len(stdout.String()) != 0 {
if len(errMsg) != 0 {
errMsg = fmt.Sprintf("%s \n\n; stdout:\n %s", errMsg, stdout.String())
errMsg = fmt.Sprintf("%s \n\n stdout:\n%s", errMsg, stdout.String())
} else {
errMsg = fmt.Sprintf("stdout:\n %s", stdout.String())
}

26
backend/utils/encrypt/encrypt_test.go

@ -1,26 +0,0 @@
package encrypt
import (
"fmt"
"testing"
"github.com/1Panel-dev/1Panel/backend/init/viper"
)
func TestStringEncrypt(t *testing.T) {
viper.Init()
p, err := StringEncrypt("1Panel@2022")
if err != nil {
t.Fatal(err)
}
fmt.Println(p)
}
func TestStringDecrypt(t *testing.T) {
viper.Init()
p, err := StringDecrypt("dXn5bVtea+KVLDrLJlpnPIJNfW8TAMmqX1QNMdSGp88=")
if err != nil {
t.Fatal(err)
}
fmt.Println(p)
}

2
frontend/src/views/cronjob/index.vue

@ -77,7 +77,7 @@
</el-button>
</template>
</el-table-column>
<el-table-column :label="$t('cronjob.cronSpec')" :min-width="120">
<el-table-column :label="$t('cronjob.cronSpec')" show-overflow-tooltip :min-width="120">
<template #default="{ row }">
<span v-if="row.specType.indexOf('N') === -1 || row.specType === 'perWeek'">
{{ $t('cronjob.' + row.specType) }}&nbsp;

Loading…
Cancel
Save