Skip to content

Commit

Permalink
feat: add task check in update
Browse files Browse the repository at this point in the history
  • Loading branch information
devhaozi committed Jul 21, 2023
1 parent fb383f9 commit 1689ef4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app/http/controllers/info_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ func (c *InfoController) Update(ctx http.Context) {
proxy := ctx.Request().InputBool("proxy")
err := tools.UpdatePanel(proxy)
if err != nil {
Error(ctx, http.StatusInternalServerError, "更新失败")
facades.Log().Error("[面板][InfoController] 更新面板失败 ", err.Error())
Error(ctx, http.StatusInternalServerError, "更新失败: "+err.Error())
return
}

Expand Down
8 changes: 8 additions & 0 deletions pkg/tools/tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@ import (
"time"

"github.com/gookit/color"
"github.com/goravel/framework/facades"
"github.com/shirou/gopsutil/cpu"
"github.com/shirou/gopsutil/disk"
"github.com/shirou/gopsutil/host"
"github.com/shirou/gopsutil/load"
"github.com/shirou/gopsutil/mem"
"github.com/shirou/gopsutil/net"
"panel/app/models"
)

// MonitoringInfo 监控信息
Expand Down Expand Up @@ -117,6 +119,12 @@ func GetLatestPanelVersion() (PanelInfo, error) {

// UpdatePanel 更新面板
func UpdatePanel(proxy bool) error {
var task models.Task
err := facades.Orm().Query().Where("status", models.TaskStatusRunning).OrWhere("status", models.TaskStatusWaiting).FirstOrFail(&task)
if err == nil {
return errors.New("面板有任务正在执行,禁止更新")
}

panelInfo, err := GetLatestPanelVersion()
if err != nil {
return err
Expand Down

0 comments on commit 1689ef4

Please sign in to comment.