mirror of
https://github.com/bcicen/ctop.git
synced 2024-08-30 18:23:19 +00:00
Merge pull request #234 from stokito/refresh
docker connector: refresh() delete container only if it not found but keep on failures
This commit is contained in:
commit
117c3bc7b5
@ -15,7 +15,6 @@ import (
|
|||||||
func init() { enabled["docker"] = NewDocker }
|
func init() { enabled["docker"] = NewDocker }
|
||||||
|
|
||||||
var actionToStatus = map[string]string{
|
var actionToStatus = map[string]string{
|
||||||
"create": "created",
|
|
||||||
"start": "running",
|
"start": "running",
|
||||||
"die": "exited",
|
"die": "exited",
|
||||||
"stop": "exited",
|
"stop": "exited",
|
||||||
@ -161,9 +160,12 @@ func ipsFormat(networks map[string]api.ContainerNetwork) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (cm *Docker) refresh(c *container.Container) {
|
func (cm *Docker) refresh(c *container.Container) {
|
||||||
insp := cm.inspect(c.Id)
|
insp, found, failed := cm.inspect(c.Id)
|
||||||
|
if failed {
|
||||||
|
return
|
||||||
|
}
|
||||||
// remove container if no longer exists
|
// remove container if no longer exists
|
||||||
if insp == nil {
|
if !found {
|
||||||
cm.delByID(c.Id)
|
cm.delByID(c.Id)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -179,14 +181,17 @@ func (cm *Docker) refresh(c *container.Container) {
|
|||||||
c.SetState(insp.State.Status)
|
c.SetState(insp.State.Status)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cm *Docker) inspect(id string) *api.Container {
|
func (cm *Docker) inspect(id string) (insp *api.Container, found bool, failed bool) {
|
||||||
c, err := cm.client.InspectContainer(id)
|
c, err := cm.client.InspectContainer(id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if _, ok := err.(*api.NoSuchContainer); !ok {
|
if _, notFound := err.(*api.NoSuchContainer); notFound {
|
||||||
|
return c, false, false
|
||||||
|
}
|
||||||
|
// other error e.g. connection failed
|
||||||
log.Errorf("%s (%T)", err.Error(), err)
|
log.Errorf("%s (%T)", err.Error(), err)
|
||||||
|
return c, false, true
|
||||||
}
|
}
|
||||||
}
|
return c, true, false
|
||||||
return c
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mark all container IDs for refresh
|
// Mark all container IDs for refresh
|
||||||
|
Loading…
Reference in New Issue
Block a user