fix: 解决本地应用升级失败的问题 (#1226)

This commit is contained in:
zhengkunwang223 2023-06-02 10:26:27 +08:00 committed by GitHub
parent bfedd02d1d
commit 90a5e741fd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 19 deletions

View file

@ -390,7 +390,11 @@ func (a AppService) SyncAppListFromLocal() {
if dirEntry.IsDir() { if dirEntry.IsDir() {
appDir := path.Join(localAppDir, dirEntry.Name()) appDir := path.Join(localAppDir, dirEntry.Name())
appDirEntries, err := os.ReadDir(appDir) appDirEntries, err := os.ReadDir(appDir)
app, err := handleLocalApp(localAppDir) if err != nil {
global.LOG.Errorf(i18n.GetMsgWithMap("ErrAppDirNull", map[string]interface{}{"name": dirEntry.Name(), "err": err.Error()}))
continue
}
app, err := handleLocalApp(appDir)
if err != nil { if err != nil {
global.LOG.Errorf(i18n.GetMsgWithMap("LocalAppErr", map[string]interface{}{"name": dirEntry.Name(), "err": err.Error()})) global.LOG.Errorf(i18n.GetMsgWithMap("LocalAppErr", map[string]interface{}{"name": dirEntry.Name(), "err": err.Error()}))
continue continue
@ -491,29 +495,27 @@ func (a AppService) SyncAppListFromLocal() {
tx, ctx := getTxAndContext() tx, ctx := getTxAndContext()
defer tx.Rollback() defer tx.Rollback()
if len(newApps) > 0 { if len(newApps) > 0 {
if err := appRepo.BatchCreate(ctx, newApps); err != nil { if err = appRepo.BatchCreate(ctx, newApps); err != nil {
return return
} }
} }
for _, update := range updateApps { for _, update := range updateApps {
if err := appRepo.Save(ctx, &update); err != nil { if err = appRepo.Save(ctx, &update); err != nil {
return return
} }
} }
if len(deleteApps) > 0 { if len(deleteApps) > 0 {
if err := appRepo.BatchDelete(ctx, deleteApps); err != nil { if err = appRepo.BatchDelete(ctx, deleteApps); err != nil {
return return
} }
if err := appDetailRepo.DeleteByAppIds(ctx, deleteAppIds); err != nil { if err = appDetailRepo.DeleteByAppIds(ctx, deleteAppIds); err != nil {
return return
} }
} }
if err := appTagRepo.DeleteByAppIds(ctx, oldAppIds); err != nil { if err = appTagRepo.DeleteByAppIds(ctx, oldAppIds); err != nil {
return return
} }
var ()
for _, newApp := range newApps { for _, newApp := range newApps {
if newApp.ID > 0 { if newApp.ID > 0 {
for _, detail := range newApp.Details { for _, detail := range newApp.Details {
@ -551,31 +553,31 @@ func (a AppService) SyncAppListFromLocal() {
} }
if len(newAppDetails) > 0 { if len(newAppDetails) > 0 {
if err := appDetailRepo.BatchCreate(ctx, newAppDetails); err != nil { if err = appDetailRepo.BatchCreate(ctx, newAppDetails); err != nil {
return return
} }
} }
for _, updateAppDetail := range updateDetails { for _, updateAppDetail := range updateDetails {
if err := appDetailRepo.Update(ctx, updateAppDetail); err != nil { if err = appDetailRepo.Update(ctx, updateAppDetail); err != nil {
return return
} }
} }
if len(deleteAppDetails) > 0 { if len(deleteAppDetails) > 0 {
if err := appDetailRepo.BatchDelete(ctx, deleteAppDetails); err != nil { if err = appDetailRepo.BatchDelete(ctx, deleteAppDetails); err != nil {
return return
} }
} }
if len(oldAppIds) > 0 { if len(oldAppIds) > 0 {
if err := appTagRepo.DeleteByAppIds(ctx, oldAppIds); err != nil { if err = appTagRepo.DeleteByAppIds(ctx, oldAppIds); err != nil {
return return
} }
} }
if len(appTags) > 0 { if len(appTags) > 0 {
if err := appTagRepo.BatchCreate(ctx, appTags); err != nil { if err = appTagRepo.BatchCreate(ctx, appTags); err != nil {
return return
} }
} }

View file

@ -664,11 +664,6 @@ func handleLocalAppDetail(versionDir string, appDetail *model.AppDetail) error {
func handleLocalApp(appDir string) (app *model.App, err error) { func handleLocalApp(appDir string) (app *model.App, err error) {
fileOp := files.NewFileOp() fileOp := files.NewFileOp()
appDirEntries, err := os.ReadDir(appDir)
if err != nil || len(appDirEntries) == 0 {
err = errors.New("ErrAppDirNull")
return
}
configYamlPath := path.Join(appDir, "data.yml") configYamlPath := path.Join(appDir, "data.yml")
if !fileOp.Stat(configYamlPath) { if !fileOp.Stat(configYamlPath) {
err = errors.New(i18n.GetMsgWithMap("ErrFileNotFound", map[string]interface{}{"name": "data.yml"})) err = errors.New(i18n.GetMsgWithMap("ErrFileNotFound", map[string]interface{}{"name": "data.yml"}))

View file

@ -27,6 +27,8 @@ const getType = (status: string) => {
return 'success'; return 'success';
case 'stopped': case 'stopped':
return 'danger'; return 'danger';
case 'unhealthy':
return 'warning';
default: default:
return ''; return '';
} }

View file

@ -448,7 +448,7 @@ const openParam = (row: any) => {
}; };
const isAppErr = (row: any) => { const isAppErr = (row: any) => {
return row.status.includes('Err') || row.status.includes('Error'); return row.status.includes('Err') || row.status.includes('Error') || row.status.includes('UnHealthy');
}; };
const quickJump = () => { const quickJump = () => {