2015-12-18 00:07:04 +00:00
|
|
|
package supervisor
|
2015-12-01 18:55:13 +00:00
|
|
|
|
2015-12-01 19:56:08 +00:00
|
|
|
import (
|
2015-12-19 00:54:02 +00:00
|
|
|
"time"
|
|
|
|
|
2015-12-01 19:56:08 +00:00
|
|
|
"github.com/Sirupsen/logrus"
|
|
|
|
"github.com/docker/containerd/runtime"
|
|
|
|
)
|
2015-12-01 18:55:13 +00:00
|
|
|
|
2016-02-12 01:26:24 +00:00
|
|
|
type DeleteTask struct {
|
2015-12-01 18:55:13 +00:00
|
|
|
s *Supervisor
|
|
|
|
}
|
|
|
|
|
2016-02-12 01:26:24 +00:00
|
|
|
func (h *DeleteTask) Handle(e *Task) error {
|
2015-12-11 19:27:33 +00:00
|
|
|
if i, ok := h.s.containers[e.ID]; ok {
|
2015-12-19 00:54:02 +00:00
|
|
|
start := time.Now()
|
2015-12-11 19:27:33 +00:00
|
|
|
if err := h.deleteContainer(i.container); err != nil {
|
2015-12-01 18:55:13 +00:00
|
|
|
logrus.WithField("error", err).Error("containerd: deleting container")
|
|
|
|
}
|
2016-02-12 01:26:24 +00:00
|
|
|
h.s.notifySubscribers(Event{
|
|
|
|
Type: "exit",
|
|
|
|
Timestamp: time.Now(),
|
|
|
|
ID: e.ID,
|
|
|
|
Status: e.Status,
|
|
|
|
Pid: e.Pid,
|
2015-12-10 20:30:04 +00:00
|
|
|
})
|
2015-12-04 23:12:57 +00:00
|
|
|
ContainersCounter.Dec(1)
|
2015-12-19 00:54:02 +00:00
|
|
|
ContainerDeleteTimer.UpdateSince(start)
|
2015-12-01 18:55:13 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-02-12 01:26:24 +00:00
|
|
|
func (h *DeleteTask) deleteContainer(container runtime.Container) error {
|
2015-12-01 18:55:13 +00:00
|
|
|
delete(h.s.containers, container.ID())
|
|
|
|
return container.Delete()
|
|
|
|
}
|