add SetStatus method to Container

This commit is contained in:
Bradley Cicenas 2017-02-03 23:33:13 +00:00
parent dbe657c9e1
commit 3f36e0c1f5
2 changed files with 11 additions and 5 deletions

View File

@ -8,6 +8,7 @@ import (
type Container struct {
id string
name string
state string
metrics collector.Metrics
collect collector.Collector
widgets widgets.ContainerWidgets
@ -21,6 +22,15 @@ func (c *Container) Collapse() {
c.widgets = widgets.NewCompact(c.id, c.name)
}
func (c *Container) SetState(s string) {
c.state = s
c.widgets.SetStatus(s)
// start collector if necessary
if s == "running" && !c.collect.Running() {
c.Collect()
}
}
func (c *Container) Collect() {
c.collect.Start()
go func() {

View File

@ -62,11 +62,7 @@ func (cm *ContainerMap) Refresh() {
removeIDs = append(removeIDs, id)
continue
}
// start collector if necessary
if states[id] == "running" && !c.collect.Running() {
c.Collect()
}
c.widgets.SetStatus(states[id])
c.SetState(states[id])
}
// remove dead containers