Gate task.Wait status check on checkpoints
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
parent
9f13b414b9
commit
fdc5a475a8
16
task.go
16
task.go
@ -8,6 +8,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
goruntime "runtime"
|
goruntime "runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
eventsapi "github.com/containerd/containerd/api/services/events/v1"
|
eventsapi "github.com/containerd/containerd/api/services/events/v1"
|
||||||
@ -93,6 +94,7 @@ type task struct {
|
|||||||
id string
|
id string
|
||||||
pid uint32
|
pid uint32
|
||||||
|
|
||||||
|
mu sync.Mutex
|
||||||
deferred *tasks.CreateTaskRequest
|
deferred *tasks.CreateTaskRequest
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,9 +104,14 @@ func (t *task) Pid() uint32 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *task) Start(ctx context.Context) error {
|
func (t *task) Start(ctx context.Context) error {
|
||||||
if t.deferred != nil {
|
t.mu.Lock()
|
||||||
response, err := t.client.TaskService().Create(ctx, t.deferred)
|
deferred := t.deferred
|
||||||
|
t.mu.Unlock()
|
||||||
|
if deferred != nil {
|
||||||
|
response, err := t.client.TaskService().Create(ctx, deferred)
|
||||||
|
t.mu.Lock()
|
||||||
t.deferred = nil
|
t.deferred = nil
|
||||||
|
t.mu.Unlock()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.io.closer.Close()
|
t.io.closer.Close()
|
||||||
return err
|
return err
|
||||||
@ -166,6 +173,10 @@ func (t *task) Wait(ctx context.Context) (uint32, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return UnknownExitStatus, errdefs.FromGRPC(err)
|
return UnknownExitStatus, errdefs.FromGRPC(err)
|
||||||
}
|
}
|
||||||
|
t.mu.Lock()
|
||||||
|
checkpoint := t.deferred != nil
|
||||||
|
t.mu.Unlock()
|
||||||
|
if !checkpoint {
|
||||||
// first check if the task has exited
|
// first check if the task has exited
|
||||||
status, err := t.Status(ctx)
|
status, err := t.Status(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -174,6 +185,7 @@ func (t *task) Wait(ctx context.Context) (uint32, error) {
|
|||||||
if status.Status == Stopped {
|
if status.Status == Stopped {
|
||||||
return status.ExitStatus, nil
|
return status.ExitStatus, nil
|
||||||
}
|
}
|
||||||
|
}
|
||||||
for {
|
for {
|
||||||
evt, err := eventstream.Recv()
|
evt, err := eventstream.Recv()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user