Skip to content

Commit

Permalink
fixed bug
Browse files Browse the repository at this point in the history
  • Loading branch information
LinkLeong committed Dec 10, 2021
1 parent 6c235d3 commit 8660b95
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
2 changes: 1 addition & 1 deletion model/sys_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,5 @@ type SystemConfig struct {
}

type CasaOSGlobalVariables struct {
AddApp bool
AppChange bool
}
4 changes: 2 additions & 2 deletions route/v1/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ func InstallApp(c *gin.Context) {
// m.PortMap = m.Port
//}
service.MyService.App().SaveContainer(md)
config.CasaOSGlobalVariables.AddApp = true
config.CasaOSGlobalVariables.AppChange = true

}()

Expand Down Expand Up @@ -743,7 +743,7 @@ func UnInstallApp(c *gin.Context) {
// }
//}
}

config.CasaOSGlobalVariables.AppChange = true
c.JSON(http.StatusOK, model.Result{Success: oasis_err2.SUCCESS, Message: oasis_err2.GetMsg(oasis_err2.SUCCESS)})

}
Expand Down
26 changes: 20 additions & 6 deletions service/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"io"
"io/ioutil"
"reflect"
"runtime"
"strings"
"sync"
Expand Down Expand Up @@ -269,7 +270,6 @@ func (a *appStruct) GetHardwareUsage() []model.DockerStatsModel {
a.GetHardwareUsageSteam()
}()
}
// 切一下,再次分配任务
runtime.Gosched()
}
list := []model.DockerStatsModel{}
Expand Down Expand Up @@ -299,11 +299,22 @@ func (a *appStruct) GetHardwareUsageSteam() {
ctx, cancel := context.WithCancel(ctx)

var lm []model2.AppListDBModel
a.db.Table(model2.CONTAINERTABLENAME).Select("label,icon,container_id").Where("origin != ?", "system").Find(&lm)
a.db.Table(model2.CONTAINERTABLENAME).Select("label,title,icon,container_id").Where("origin != ?", "system").Find(&lm)
var list []types.ContainerStats
for i := 0; i < 100; i++ {
if config.CasaOSGlobalVariables.AddApp {
a.db.Table(model2.CONTAINERTABLENAME).Select("label,icon,container_id").Where("origin != ?", "system").Find(&lm)
if config.CasaOSGlobalVariables.AppChange {
lm = []model2.AppListDBModel{}
config.CasaOSGlobalVariables.AppChange = false
a.db.Table(model2.CONTAINERTABLENAME).Select("label,title,icon,container_id").Where("origin != ?", "system").Find(&lm)
dataApps := dataStr
lock.Lock()
dataStr = make(map[string]model.DockerStatsModel)
for _, v := range lm {
if !reflect.DeepEqual(dataApps[v.ContainerId], model.DockerStatsModel{}) {
dataStr[v.ContainerId] = dataApps[v.ContainerId]
}
}
lock.Unlock()
}
var wg sync.WaitGroup
for _, v := range lm {
Expand All @@ -322,10 +333,13 @@ func (a *appStruct) GetHardwareUsageSteam() {
lock.Lock()
dockerStats := model.DockerStatsModel{}
dockerStats.Pre = dataStr[v.ContainerId].Data

dockerStats.Data = data
dockerStats.Icon = v.Icon
dockerStats.Title = v.Label
if len(v.Label) > 0 {
dockerStats.Title = v.Label
} else {
dockerStats.Title = v.Title
}
dataStr[v.ContainerId] = dockerStats
lock.Unlock()
}(v, lock)
Expand Down

0 comments on commit 8660b95

Please sign in to comment.