本文整理汇总了Golang中github.com/docker/containerd/api/grpc/types.APIClient.Events方法的典型用法代码示例。如果您正苦于以下问题:Golang APIClient.Events方法的具体用法?Golang APIClient.Events怎么用?Golang APIClient.Events使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/docker/containerd/api/grpc/types.APIClient
的用法示例。
在下文中一共展示了APIClient.Events方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: containerEvents
func containerEvents(c types.APIClient, container string) <-chan *types.Event {
evChan := make(chan *types.Event)
ts := time.Now()
go func() {
for {
tsp, err := ptypes.TimestampProto(ts)
if err != nil {
close(evChan)
return
}
events, err := c.Events(netcontext.Background(), &types.EventsRequest{Timestamp: tsp})
if err != nil {
fmt.Printf("c.Events error: %v", err)
// TODO try to find a way to kill the process ?
close(evChan)
return
}
for {
e, err := events.Recv()
if err != nil {
time.Sleep(1 * time.Second)
break
}
ts, err = ptypes.Timestamp(e.Timestamp)
if e.Id == container {
evChan <- e
}
}
}
}()
return evChan
}
示例2: waitForExit
func waitForExit(c types.APIClient, events types.API_EventsClient, id, pid string, closer func()) {
timestamp := time.Now()
for {
e, err := events.Recv()
if err != nil {
if grpc.ErrorDesc(err) == transport.ErrConnClosing.Desc {
closer()
os.Exit(128 + int(syscall.SIGHUP))
}
time.Sleep(1 * time.Second)
tsp, err := ptypes.TimestampProto(timestamp)
if err != nil {
closer()
fmt.Fprintf(os.Stderr, "%s", err.Error())
os.Exit(1)
}
events, _ = c.Events(netcontext.Background(), &types.EventsRequest{Timestamp: tsp})
continue
}
timestamp, err = ptypes.Timestamp(e.Timestamp)
if e.Id == id && e.Type == "exit" && e.Pid == pid {
closer()
os.Exit(int(e.Status))
}
}
}
示例3: waitForExit
func waitForExit(c types.APIClient, events types.API_EventsClient, id, pid string, closer func()) {
timestamp := uint64(time.Now().Unix())
for {
e, err := events.Recv()
if err != nil {
time.Sleep(1 * time.Second)
events, _ = c.Events(netcontext.Background(), &types.EventsRequest{Timestamp: timestamp})
continue
}
timestamp = e.Timestamp
if e.Id == id && e.Type == "exit" && e.Pid == pid {
closer()
os.Exit(int(e.Status))
}
}
}