use event service for task wait
Signed-off-by: Evan Hazlett <ejhazlett@gmail.com> Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:

committed by
Michael Crosby

parent
440fc06041
commit
0b06fa8518
30
task.go
30
task.go
@@ -11,9 +11,13 @@ import (
|
||||
"syscall"
|
||||
|
||||
"github.com/containerd/containerd/api/services/containers"
|
||||
eventsapi "github.com/containerd/containerd/api/services/events"
|
||||
"github.com/containerd/containerd/api/services/execution"
|
||||
"github.com/containerd/containerd/api/types/event"
|
||||
tasktypes "github.com/containerd/containerd/api/types/task"
|
||||
"github.com/containerd/containerd/content"
|
||||
"github.com/containerd/containerd/rootfs"
|
||||
"github.com/gogo/protobuf/proto"
|
||||
"github.com/opencontainers/image-spec/specs-go/v1"
|
||||
specs "github.com/opencontainers/runtime-spec/specs-go"
|
||||
)
|
||||
@@ -138,7 +142,31 @@ func (t *task) Status(ctx context.Context) (TaskStatus, error) {
|
||||
|
||||
// Wait is a blocking call that will wait for the task to exit and return the exit status
|
||||
func (t *task) Wait(ctx context.Context) (uint32, error) {
|
||||
return 255, fmt.Errorf("not implemented")
|
||||
// TODO (ehazlett): add filtering for specific event
|
||||
events, err := t.client.EventService().Stream(ctx, &eventsapi.StreamEventsRequest{})
|
||||
if err != nil {
|
||||
return UnknownExitStatus, err
|
||||
}
|
||||
for {
|
||||
evt, err := events.Recv()
|
||||
if err != nil {
|
||||
return UnknownExitStatus, err
|
||||
}
|
||||
if evt.Event.TypeUrl == "types.containerd.io/containerd.v1.types.event.RuntimeEvent" {
|
||||
e := &event.RuntimeEvent{}
|
||||
if err := proto.Unmarshal(evt.Event.Value, e); err != nil {
|
||||
return UnknownExitStatus, err
|
||||
}
|
||||
|
||||
if e.Type != tasktypes.Event_EXIT {
|
||||
continue
|
||||
}
|
||||
|
||||
if e.ID == t.containerID && e.Pid == t.pid {
|
||||
return e.ExitStatus, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Delete deletes the task and its runtime state
|
||||
|
Reference in New Issue
Block a user