6bfc4df8a7
Signed-off-by: Alexander Morozov <lk4d4@docker.com>
62 lines
1.1 KiB
Go
62 lines
1.1 KiB
Go
package containerd
|
|
|
|
import (
|
|
"sync"
|
|
"time"
|
|
|
|
"github.com/Sirupsen/logrus"
|
|
"github.com/docker/containerd/runtime"
|
|
)
|
|
|
|
type Worker interface {
|
|
Start()
|
|
}
|
|
|
|
type StartTask struct {
|
|
Container runtime.Container
|
|
Checkpoint string
|
|
Err chan error
|
|
}
|
|
|
|
func NewWorker(s *Supervisor, wg *sync.WaitGroup) Worker {
|
|
return &worker{
|
|
s: s,
|
|
wg: wg,
|
|
}
|
|
}
|
|
|
|
type worker struct {
|
|
wg *sync.WaitGroup
|
|
s *Supervisor
|
|
}
|
|
|
|
func (w *worker) Start() {
|
|
defer w.wg.Done()
|
|
for t := range w.s.tasks {
|
|
started := time.Now()
|
|
logrus.WithFields(logrus.Fields{
|
|
"containerID": t.Container.ID(),
|
|
"checkpoint": t.Checkpoint,
|
|
"started": started,
|
|
}).Debug("worker received task")
|
|
if t.Checkpoint != "" {
|
|
if err := t.Container.Restore(t.Checkpoint); err != nil {
|
|
evt := NewEvent(DeleteEventType)
|
|
evt.ID = t.Container.ID()
|
|
w.s.SendEvent(evt)
|
|
t.Err <- err
|
|
continue
|
|
}
|
|
} else {
|
|
if err := t.Container.Start(); err != nil {
|
|
evt := NewEvent(DeleteEventType)
|
|
evt.ID = t.Container.ID()
|
|
w.s.SendEvent(evt)
|
|
t.Err <- err
|
|
continue
|
|
}
|
|
}
|
|
ContainerStartTimer.UpdateSince(started)
|
|
t.Err <- nil
|
|
}
|
|
}
|