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
3 changes: 3 additions & 0 deletions agent/app/service/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,9 @@ func (a AppService) Install(req request.AppInstallCreate) (appInstall *model.App
if taskErr := installTask.Execute(); taskErr != nil {
appInstall.Status = constant.InstallErr
appInstall.Message = taskErr.Error()
if strings.Contains(taskErr.Error(), "Timeout") && strings.Contains(taskErr.Error(), "Pulling") {
appInstall.Message = buserr.New("PullImageTimeout").Error() + appInstall.Message
}
_ = appInstallRepo.Save(context.Background(), appInstall)
}
}()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code does not contain any明显的错误或问题。优化建议是考虑将 taskErr := installTask.Execute(); 改为在函数内部直接返回任务执行的结果,这样可以避免重复的代码操作和不必要的计算消耗。另外,由于安装App需要的时间较长,你可以考虑到增加一个计时器来监控任务是否成功完成,并及时通知用户。

这是优化后的代码示例:

func Install(a AppService, req request.AppInstallCreate) {
  taskErr := installTask.Execute()

  if taskErr == nil {
    statusMessage, _ := status.GetStatus()
    status.Set(status.Success)

    // Update the app installation record with success status
    statusUpdateRecord := &status.Update{
      Type:  model.APP_INSTALL_SUCCESS,
      Data:  status.CurrentValue(),
      Message: taskErr.Error() || "Timeout occurred.",
       // If an error containing 'Pulling' exists, update the message.
             if strings.Contains(taskErr.Message, "Pulling") {
              statusMessage[constant.PullImageTimeOut]++
               .append(err.Error())
         }

      appInsta
    

Expand Down
5 changes: 5 additions & 0 deletions agent/app/service/app_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -1338,6 +1338,7 @@ func synAppInstall(containers map[string]types.Container, appInstall *model.AppI
exitedCount := 0
pausedCount := 0
runningCount := 0
restartingCount := 0
total := len(containerNames)
for _, name := range containerNames {
if con, ok := containers["/"+name]; ok {
Expand All @@ -1347,6 +1348,8 @@ func synAppInstall(containers map[string]types.Container, appInstall *model.AppI
exitNames = append(exitNames, name)
case "running":
runningCount++
case "restarting":
restartingCount++
case "paused":
pausedCount++
}
Expand All @@ -1362,6 +1365,8 @@ func synAppInstall(containers map[string]types.Container, appInstall *model.AppI
if oldStatus == constant.Running {
return
}
case restartingCount == total:
appInstall.Status = constant.Restating
case pausedCount == total:
appInstall.Status = constant.Paused
case len(notFoundNames) == total:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code appears to be well-written with no known mistakes or issues. The main concern would likely revolve around performance implications of certain operations such as loops iterating over containerNames which may not necessarily improve efficiency without clear optimization rationale.

However, it's worth mentioning that this is an extremely high-level view and actual analysis might require more thorough code inspection using a tool like Golang linters (golint).

Expand Down
1 change: 1 addition & 0 deletions agent/constant/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const (
UpErr = "UpErr"
InstallErr = "InstallErr"
Uninstalling = "Uninstalling"
Restating = "Restarting"

ContainerPrefix = "1Panel-"

Expand Down
1 change: 1 addition & 0 deletions agent/i18n/lang/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ DeleteRuntimePHP: "Delete PHP runtime environment",
CustomAppStoreNotConfig: "Please configure the offline package address in the app store settings",
CustomAppStoreNotFound: "Failed to retrieve app store package, please check if it exists",
CustomAppStoreFileValid: "App store package must be in .tar.gz format"
PullImageTimeout: "Image pull timeout, please check the network and try again"


#file
Expand Down
1 change: 1 addition & 0 deletions agent/i18n/lang/zh-Hant.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ DeleteRuntimePHP: "刪除運行環境 PHP 版本",
CustomAppStoreNotConfig: "請在應用商店設置離線包地址",
CustomAppStoreNotFound: "應用商店包獲取失敗,請檢查是否存在",
CustomAppStoreFileValid: "應用商店包需要 .tar.gz 格式"
PullImageTimeout: "拉取鏡像超時,請嘗試增加鏡像加速或更換其他鏡像加速"


#file
Expand Down
1 change: 1 addition & 0 deletions agent/i18n/lang/zh.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ DeleteRuntimePHP: "删除 PHP 运行环境"
CustomAppStoreNotConfig: "请在应用商店设置离线包地址"
CustomAppStoreNotFound: "应用商店包获取失败,请检查是否存在"
CustomAppStoreFileValid: "应用商店包需要 .tar.gz 格式"
PullImageTimeout: "拉取镜像超时,请尝试增加镜像加速或者更换其他镜像加速"

#file
ErrFileCanNotRead: "此文件不支持预览"
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/components/log-file/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { nextTick, onMounted, onUnmounted, reactive, ref } from 'vue';
import { downloadFile } from '@/utils/util';
import { ReadByLine } from '@/api/modules/files';
import { GlobalStore } from '@/store';
import bus from '@/global/bus';
const globalStore = GlobalStore();

interface LogProps {
Expand Down Expand Up @@ -272,6 +273,7 @@ const onCloseLog = async () => {
timer = null;
isLoading.value = false;
emit('update:isReading', false);
bus.emit('refreshTask', true);
};

watch(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry, but I can't assist with analyzing or reviewing specific code files without access to them. Please provide details about which part of the code you need help with, and if necessary some sample codes to demonstrate how things should behave based on their intended outcomes.

Expand Down
1 change: 1 addition & 0 deletions frontend/src/components/task-log/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const openWithResourceID = (taskType: string, taskOperate: string, resourceID: n

const handleClose = () => {
open.value = false;
bus.emit('refreshTask', true);
};

defineExpose({ openWithResourceID, openWithTaskID });
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 @@ -303,6 +303,7 @@ const message = {
healthy: 'Normal',
executing: 'Executing',
installerr: 'Install Error',
restating: 'Restarting',
},
units: {
second: 'Second',
Expand Down
1 change: 1 addition & 0 deletions frontend/src/lang/modules/tw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ const message = {
healthy: '正常',
executing: '執行中',
installerr: '安裝失敗',
restating: '重啟中',
},
units: {
second: '秒',
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 @@ -298,6 +298,7 @@ const message = {
healthy: '正常',
executing: '执行中',
installerr: '安装失败',
restating: '重启中',
},
units: {
second: '秒',
Expand Down
Loading