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/response/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ type AppService struct {
Value string `json:"value"`
Config interface{} `json:"config"`
From string `json:"from"`
Status string `json:"status"`
}

type AppParam struct {
Expand Down
2 changes: 1 addition & 1 deletion agent/app/service/ai.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ func LoadContainerName() (string, error) {
if err != nil {
return "", fmt.Errorf("ollama service is not found, err: %v", err)
}
if ollamaBaseInfo.Status != constant.Running {
if ollamaBaseInfo.Status != constant.StatusRunning {
return "", fmt.Errorf("container %s of ollama is not running, please check and retry!", ollamaBaseInfo.ContainerName)
}
return ollamaBaseInfo.ContainerName, nil
Expand Down
23 changes: 16 additions & 7 deletions agent/app/service/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,15 @@ func (a AppService) Install(req request.AppInstallCreate) (appInstall *model.App
return
}
}
if hostName, ok := req.Params["PANEL_DB_HOST"]; ok {
database, _ := databaseRepo.Get(repo.WithByName(hostName.(string)))
if database.AppInstallID > 0 {
databaseInstall, _ := appInstallRepo.GetFirst(repo.WithByID(database.AppInstallID))
if databaseInstall.Status != constant.StatusRunning {
return nil, buserr.WithName("ErrAppIsDown", databaseInstall.Name)
}
}
}
if app.Key == "openresty" && app.Resource == "remote" && common.CompareVersion(appDetail.Version, "1.27") {
if dir, ok := req.Params["WEBSITE_DIR"]; ok {
siteDir := dir.(string)
Expand Down Expand Up @@ -421,7 +430,7 @@ func (a AppService) Install(req request.AppInstallCreate) (appInstall *model.App
AppId: appDetail.AppId,
AppDetailId: appDetail.ID,
Version: appDetail.Version,
Status: constant.Installing,
Status: constant.StatusInstalling,
HttpPort: httpPort,
HttpsPort: httpsPort,
App: app,
Expand Down Expand Up @@ -536,7 +545,7 @@ func (a AppService) Install(req request.AppInstallCreate) (appInstall *model.App
}

handleAppStatus := func(t *task.Task) {
appInstall.Status = constant.UpErr
appInstall.Status = constant.StatusUpErr
appInstall.Message = installTask.Task.ErrorMsg
_ = appInstallRepo.Save(context.Background(), appInstall)
}
Expand All @@ -545,7 +554,7 @@ func (a AppService) Install(req request.AppInstallCreate) (appInstall *model.App

go func() {
if taskErr := installTask.Execute(); taskErr != nil {
appInstall.Status = constant.InstallErr
appInstall.Status = constant.StatusInstallErr
appInstall.Message = taskErr.Error()
if strings.Contains(taskErr.Error(), "Timeout") && strings.Contains(taskErr.Error(), "Pulling") {
appInstall.Message = buserr.New("PullImageTimeout").Error() + appInstall.Message
Expand Down Expand Up @@ -808,7 +817,7 @@ func (a AppService) GetAppUpdate() (*response.AppUpdateRes, error) {
if err != nil {
return nil, err
}
if setting.AppStoreSyncStatus == constant.Syncing {
if setting.AppStoreSyncStatus == constant.StatusSyncing {
res.IsSyncing = true
return res, nil
}
Expand Down Expand Up @@ -931,7 +940,7 @@ func (a AppService) SyncAppListFromRemote(taskID string) (err error) {
list = updateRes.AppList
}
settingService := NewISettingService()
_ = settingService.Update("AppStoreSyncStatus", constant.Syncing)
_ = settingService.Update("AppStoreSyncStatus", constant.StatusSyncing)

setting, err := settingService.GetSettingInfo()
if err != nil {
Expand Down Expand Up @@ -1156,7 +1165,7 @@ func (a AppService) SyncAppListFromRemote(taskID string) (err error) {
}
tx.Commit()

_ = settingService.Update("AppStoreSyncStatus", constant.SyncSuccess)
_ = settingService.Update("AppStoreSyncStatus", constant.StatusSyncSuccess)
_ = settingService.Update("AppStoreLastModified", strconv.Itoa(list.LastModified))
t.Log(i18n.GetMsgByKey("AppStoreSyncSuccess"))
return nil
Expand All @@ -1165,7 +1174,7 @@ func (a AppService) SyncAppListFromRemote(taskID string) (err error) {
go func() {
if err = syncTask.Execute(); err != nil {
_ = NewISettingService().Update("AppStoreLastModified", "0")
_ = NewISettingService().Update("AppStoreSyncStatus", constant.Error)
_ = NewISettingService().Update("AppStoreSyncStatus", constant.StatusError)
}
}()

Expand Down
15 changes: 9 additions & 6 deletions agent/app/service/app_install.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,11 +406,11 @@ func (a *AppInstallService) Update(req request.AppInstalledUpdate) error {
_ = fileOp.WriteFile(installed.GetComposePath(), strings.NewReader(backupDockerCompose), constant.DirPerm)
return err
}
installed.Status = constant.Running
installed.Status = constant.StatusRunning
_ = appInstallRepo.Save(context.Background(), &installed)

website, _ := websiteRepo.GetFirst(websiteRepo.WithAppInstallId(installed.ID))
if changePort && website.ID != 0 && website.Status == constant.Running {
if changePort && website.ID != 0 && website.Status == constant.StatusRunning {
go func() {
nginxInstall, err := getNginxFull(&website)
if err != nil {
Expand Down Expand Up @@ -455,9 +455,9 @@ func (a *AppInstallService) SyncAll(systemInit bool) error {
return err
}
for _, i := range allList {
if i.Status == constant.Installing || i.Status == constant.Upgrading || i.Status == constant.Rebuilding || i.Status == constant.Uninstalling {
if i.Status == constant.StatusInstalling || i.Status == constant.StatusUpgrading || i.Status == constant.StatusRebuilding || i.Status == constant.StatusUninstalling {
if systemInit {
i.Status = constant.Error
i.Status = constant.StatusError
i.Message = "1Panel restart causes the task to terminate"
_ = appInstallRepo.Save(context.Background(), &i)
}
Expand Down Expand Up @@ -498,8 +498,10 @@ func (a *AppInstallService) GetServices(key string) ([]response.AppService, erro
}
service.Config = paramMap
service.From = constant.AppResourceLocal
service.Status = install.Status
} else {
service.From = constant.AppResourceRemote
service.Status = constant.StatusRunning
}
res = append(res, service)
}
Expand All @@ -508,7 +510,7 @@ func (a *AppInstallService) GetServices(key string) ([]response.AppService, erro
if err != nil {
return nil, err
}
installs, err := appInstallRepo.ListBy(appInstallRepo.WithAppId(app.ID), appInstallRepo.WithStatus(constant.Running))
installs, err := appInstallRepo.ListBy(appInstallRepo.WithAppId(app.ID), appInstallRepo.WithStatus(constant.StatusRunning))
if err != nil {
return nil, err
}
Expand All @@ -521,6 +523,7 @@ func (a *AppInstallService) GetServices(key string) ([]response.AppService, erro
Label: install.Name,
Value: install.ServiceName,
Config: paramMap,
Status: install.Status,
})
}
}
Expand Down Expand Up @@ -774,7 +777,7 @@ func (a *AppInstallService) GetParams(id uint) (*response.AppConfig, error) {
}

func syncAppInstallStatus(appInstall *model.AppInstall, force bool) error {
if appInstall.Status == constant.Installing || appInstall.Status == constant.Rebuilding || appInstall.Status == constant.Upgrading || appInstall.Status == constant.Uninstalling {
if appInstall.Status == constant.StatusInstalling || appInstall.Status == constant.StatusRebuilding || appInstall.Status == constant.StatusUpgrading || appInstall.Status == constant.StatusUninstalling {
return nil
}
cli, err := docker.NewClient()
Expand Down
50 changes: 25 additions & 25 deletions agent/app/service/app_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ func deleteAppInstall(deleteReq request.AppInstallDelete) error {
}

uninstall := func(t *task.Task) error {
install.Status = constant.Uninstalling
install.Status = constant.StatusUninstalling
_ = appInstallRepo.Save(context.Background(), &install)
dir, _ := os.Stat(appDir)
if dir != nil {
Expand Down Expand Up @@ -434,7 +434,7 @@ func deleteAppInstall(deleteReq request.AppInstallDelete) error {
uninstallTask.AddSubTask(task.GetTaskName(install.Name, task.TaskUninstall, task.TaskScopeApp), uninstall, nil)
go func() {
if err := uninstallTask.Execute(); err != nil && !deleteReq.ForceDelete {
install.Status = constant.Error
install.Status = constant.StatusError
_ = appInstallRepo.Save(context.Background(), &install)
}
}()
Expand Down Expand Up @@ -554,7 +554,7 @@ func upgradeInstall(req request.AppInstallUpgrade) error {
if err != nil {
return err
}
install.Status = constant.Upgrading
install.Status = constant.StatusUpgrading

var (
upErr error
Expand Down Expand Up @@ -747,7 +747,7 @@ func upgradeInstall(req request.AppInstallUpgrade) error {
return err
}
t.LogSuccess(logStr)
install.Status = constant.Running
install.Status = constant.StatusRunning
return appInstallRepo.Save(context.Background(), &install)
}

Expand All @@ -769,8 +769,8 @@ func upgradeInstall(req request.AppInstallUpgrade) error {
err = upgradeTask.Execute()
if err != nil {
existInstall, _ := appInstallRepo.GetFirst(repo.WithByID(req.InstallID))
if existInstall.ID > 0 && existInstall.Status != constant.Running {
existInstall.Status = constant.UpgradeErr
if existInstall.ID > 0 && existInstall.Status != constant.StatusRunning {
existInstall.Status = constant.StatusUpgradeErr
existInstall.Message = err.Error()
_ = appInstallRepo.Save(context.Background(), &existInstall)
}
Expand Down Expand Up @@ -889,7 +889,7 @@ func downloadApp(app model.App, appDetail model.AppDetail, appInstall *model.App
defer func() {
if err != nil {
if appInstall != nil {
appInstall.Status = constant.DownloadErr
appInstall.Status = constant.StatusDownloadErr
appInstall.Message = err.Error()
}
}
Expand Down Expand Up @@ -1105,18 +1105,18 @@ func upApp(task *task.Task, appInstall *model.AppInstall, pullImages bool) error
if appInstall.Message == "" {
appInstall.Message = err.Error()
}
appInstall.Status = constant.UpErr
appInstall.Status = constant.StatusUpErr
_ = appInstallRepo.Save(context.Background(), appInstall)
return err
} else {
appInstall.Status = constant.Running
appInstall.Status = constant.StatusRunning
_ = appInstallRepo.Save(context.Background(), appInstall)
return nil
}
}

func rebuildApp(appInstall model.AppInstall) error {
appInstall.Status = constant.Rebuilding
appInstall.Status = constant.StatusRebuilding
_ = appInstallRepo.Save(context.Background(), &appInstall)
go func() {
dockerComposePath := appInstall.GetComposePath()
Expand All @@ -1137,7 +1137,7 @@ func rebuildApp(appInstall model.AppInstall) error {
}
appInstall.ContainerName = strings.Join(containerNames, ",")

appInstall.Status = constant.Running
appInstall.Status = constant.StatusRunning
_ = appInstallRepo.Save(context.Background(), &appInstall)
}()
return nil
Expand Down Expand Up @@ -1336,24 +1336,24 @@ func handleErr(install model.AppInstall, err error, out string) error {
install.Message = out
reErr = errors.New(out)
}
install.Status = constant.UpErr
install.Status = constant.StatusUpErr
_ = appInstallRepo.Save(context.Background(), &install)
return reErr
}

func doNotNeedSync(installed model.AppInstall) bool {
return installed.Status == constant.Installing || installed.Status == constant.Rebuilding || installed.Status == constant.Upgrading ||
installed.Status == constant.Syncing || installed.Status == constant.Uninstalling || installed.Status == constant.InstallErr
return installed.Status == constant.StatusInstalling || installed.Status == constant.StatusRebuilding || installed.Status == constant.StatusUpgrading ||
installed.Status == constant.StatusSyncing || installed.Status == constant.StatusUninstalling || installed.Status == constant.StatusInstallErr
}

func synAppInstall(containers map[string]types.Container, appInstall *model.AppInstall, force bool) {
oldStatus := appInstall.Status
containerNames := strings.Split(appInstall.ContainerName, ",")
if len(containers) == 0 {
if appInstall.Status == constant.UpErr && !force {
if appInstall.Status == constant.StatusUpErr && !force {
return
}
appInstall.Status = constant.Error
appInstall.Status = constant.StatusError
appInstall.Message = buserr.WithName("ErrContainerNotFound", strings.Join(containerNames, ",")).Error()
_ = appInstallRepo.Save(context.Background(), appInstall)
return
Expand Down Expand Up @@ -1384,21 +1384,21 @@ func synAppInstall(containers map[string]types.Container, appInstall *model.AppI
}
switch {
case exitedCount == total:
appInstall.Status = constant.Stopped
appInstall.Status = constant.StatusStopped
case runningCount == total:
appInstall.Status = constant.Running
if oldStatus == constant.Running {
appInstall.Status = constant.StatusRunning
if oldStatus == constant.StatusRunning {
return
}
case restartingCount == total:
appInstall.Status = constant.Restating
appInstall.Status = constant.StatusRestarting
case pausedCount == total:
appInstall.Status = constant.Paused
appInstall.Status = constant.StatusPaused
case len(notFoundNames) == total:
if appInstall.Status == constant.UpErr && !force {
if appInstall.Status == constant.StatusUpErr && !force {
return
}
appInstall.Status = constant.Error
appInstall.Status = constant.StatusError
appInstall.Message = buserr.WithName("ErrContainerNotFound", strings.Join(notFoundNames, ",")).Error()
default:
var msg string
Expand All @@ -1412,7 +1412,7 @@ func synAppInstall(containers map[string]types.Container, appInstall *model.AppI
msg = buserr.New("ErrAppWarn").Error()
}
appInstall.Message = msg
appInstall.Status = constant.UnHealthy
appInstall.Status = constant.StatusUnHealthy
}
_ = appInstallRepo.Save(context.Background(), appInstall)
}
Expand Down Expand Up @@ -1761,7 +1761,7 @@ func getMajorVersion(version string) string {
}

func ignoreUpdate(installed model.AppInstall) bool {
if installed.App.Type == "php" || installed.Status == constant.Installing {
if installed.App.Type == "php" || installed.Status == constant.StatusInstalling {
return true
}
if installed.App.Key == constant.AppMysql {
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 has no apparent issues or irregularities according to the provided snippet. It appears to be correctly implemented.

However, since it is from 2021 and there may have been some changes made later that could introduce bugs, I suggest comparing this snapshot against more recent versions of the source codebase to ensure best practices are being followed. If you're looking for specific recommendations based on current knowledge, feel free to ask!

Expand Down
1 change: 1 addition & 0 deletions agent/app/service/backup_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ func (u *BackupRecordService) LoadRecordSize(req dto.SearchForSize) ([]dto.Recor
default:
_, records, err := backupRepo.PageRecord(
req.Page, req.PageSize,
repo.WithOrderBy("created_at desc"),
repo.WithByName(req.Name),
repo.WithByType(req.Type),
repo.WithByDetailName(req.DetailName),
Expand Down
4 changes: 2 additions & 2 deletions agent/app/service/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ type logOption struct {
func (u *DockerService) LoadDockerStatus() string {
client, err := docker.NewDockerClient()
if err != nil {
return constant.Stopped
return constant.StatusStopped
}
defer client.Close()
if _, err := client.Ping(context.Background()); err != nil {
return constant.Stopped
return constant.StatusStopped
}

return constant.StatusRunning
Expand Down
4 changes: 2 additions & 2 deletions agent/app/service/snapshot_recover.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,13 +303,13 @@ func recoverAppData(src string, itemHelper *snapRecoverHelper) error {
var wg sync.WaitGroup
for i := 0; i < len(appInstalls); i++ {
wg.Add(1)
appInstalls[i].Status = constant.Rebuilding
appInstalls[i].Status = constant.StatusRebuilding
_ = appInstallRepo.Save(context.Background(), &appInstalls[i])
go func(app model.AppInstall) {
defer wg.Done()
dockerComposePath := app.GetComposePath()
_, _ = compose.Up(dockerComposePath)
app.Status = constant.Running
app.Status = constant.StatusRunning
_ = appInstallRepo.Save(context.Background(), &app)
}(appInstalls[i])
}
Expand Down
2 changes: 1 addition & 1 deletion agent/app/service/website.go
Original file line number Diff line number Diff line change
Expand Up @@ -1153,7 +1153,7 @@ func (w WebsiteService) PreInstallCheck(req request.WebsiteInstallCheckReq) ([]r
Version: install.Version,
AppName: install.App.Name,
})
if install.Status != constant.Running {
if install.Status != constant.StatusRunning {
showErr = true
}
}
Expand Down
2 changes: 1 addition & 1 deletion agent/app/service/website_ssl.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ func (w WebsiteSSLService) ObtainSSL(apply request.WebsiteSSLApply) error {

func handleError(websiteSSL *model.WebsiteSSL, err error) {
if websiteSSL.Status == constant.SSLInit || websiteSSL.Status == constant.SSLError {
websiteSSL.Status = constant.Error
websiteSSL.Status = constant.StatusError
} else {
websiteSSL.Status = constant.SSLApplyError
}
Expand Down
Loading
Loading