From 3bcb5800a2d37a757544649cd2fa1948020f04c9 Mon Sep 17 00:00:00 2001 From: ssongliu <73214554+ssongliu@users.noreply.github.com> Date: Thu, 14 Sep 2023 14:06:13 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A7=A3=E5=86=B3=E5=BF=AB=E7=85=A7?= =?UTF-8?q?=E6=81=A2=E5=A4=8D=E6=97=B6=E5=BA=94=E7=94=A8=E9=87=8D=E5=BB=BA?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E6=8B=89=E8=B5=B7=E7=9A=84=E9=97=AE=E9=A2=98?= =?UTF-8?q?=20(#2287)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/service/snapshot.go | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/backend/app/service/snapshot.go b/backend/app/service/snapshot.go index ceaf76df2..ebb80ddc7 100644 --- a/backend/app/service/snapshot.go +++ b/backend/app/service/snapshot.go @@ -17,6 +17,7 @@ import ( "github.com/1Panel-dev/1Panel/backend/constant" "github.com/1Panel-dev/1Panel/backend/global" "github.com/1Panel-dev/1Panel/backend/utils/cmd" + "github.com/1Panel-dev/1Panel/backend/utils/compose" "github.com/1Panel-dev/1Panel/backend/utils/docker" "github.com/1Panel-dev/1Panel/backend/utils/files" "github.com/jinzhu/copier" @@ -957,14 +958,35 @@ func (u *SnapshotService) handleUnTar(sourceDir, targetDir string) error { } func rebuildAllAppInstall() error { + global.LOG.Debug("start to rebuild all app") appInstalls, err := appInstallRepo.ListBy() if err != nil { global.LOG.Errorf("get all app installed for rebuild failed, err: %v", err) return err } - for _, install := range appInstalls { - _ = rebuildApp(install) + var wg sync.WaitGroup + for i := 0; i < len(appInstalls); i++ { + wg.Add(1) + appInstalls[i].Status = constant.Rebuilding + _ = appInstallRepo.Save(context.Background(), &appInstalls[i]) + go func(app model.AppInstall) { + defer wg.Done() + dockerComposePath := app.GetComposePath() + out, err := compose.Down(dockerComposePath) + if err != nil { + _ = handleErr(app, err, out) + return + } + out, err = compose.Up(dockerComposePath) + if err != nil { + _ = handleErr(app, err, out) + return + } + app.Status = constant.Running + _ = appInstallRepo.Save(context.Background(), &app) + }(appInstalls[i]) } + wg.Wait() return nil }