當前位置: 首頁>>代碼示例>>Golang>>正文


Golang APIClient.Events方法代碼示例

本文整理匯總了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
}
開發者ID:hyperhq,項目名稱:runv,代碼行數:32,代碼來源:main.go

示例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))
		}
	}
}
開發者ID:estesp,項目名稱:containerd,代碼行數:26,代碼來源:container.go

示例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))
		}
	}
}
開發者ID:carriercomm,項目名稱:containerd,代碼行數:16,代碼來源:container.go


注:本文中的github.com/docker/containerd/api/grpc/types.APIClient.Events方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。