本文整理汇总了Golang中github.com/koding/kite.Client.TellWithTimeout方法的典型用法代码示例。如果您正苦于以下问题:Golang Client.TellWithTimeout方法的具体用法?Golang Client.TellWithTimeout怎么用?Golang Client.TellWithTimeout使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/koding/kite.Client
的用法示例。
在下文中一共展示了Client.TellWithTimeout方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: checkTunnel
func (s *Stack) checkTunnel(c *kite.Client) error {
resp, err := c.TellWithTimeout("tunnel.info", 2*time.Minute)
if err != nil {
return err
}
var info tunnel.InfoResponse
if err := resp.Unmarshal(&info); err != nil {
return err
}
s.Log.Debug("received tunnel.info response: %+v", &info)
if info.State != tunnel.StateConnected {
// We do not fail here, as the tunnel can be recovering
// and we might hit the window when it's not yet done.
// However we log, to show kloud observed problems with
// connection.
s.Log.Warning("%s: want tunnel to be %q, was %q instead", c.ID, tunnel.StateConnected, info.State)
return nil
}
if _, ok := info.Ports["kite"]; !ok {
// Every klient has its connection to kontrol tunneled, thus
// tunnel.info should report ports for kite. Warn if there're
// none to show kloud observed unexpected behavior.
// However it is not critical though, as we were able to
// kite.ping the klient, it means the klient may have some
// other problems (connection with host kite etc.).
s.Log.Warning("%s: no ports for kite", c.ID)
}
return nil
}
示例2: watch
// watch watches the events of the specified event type.
func watch(k *kite.Client, eventType string, eventId string, interval time.Duration) error {
eventArgs := stack.EventArgs([]stack.EventArg{
{
Type: eventType,
EventId: eventId,
},
})
for {
resp, err := k.TellWithTimeout("event", defaultTellTimeout, eventArgs)
if err != nil {
return err
}
var events []stack.EventResponse
if err := resp.Unmarshal(&events); err != nil {
return err
}
if len(events) == 0 {
return errors.New("incoming event response is not an array")
}
if events[0].Error != nil {
return events[0].Error
}
DefaultUi.Info(fmt.Sprintf("%s ==> %s [Status: %s Percentage: %d]",
fmt.Sprint(time.Now())[:19],
events[0].Event.Message,
events[0].Event.Status,
events[0].Event.Percentage,
))
if events[0].Event.Error != "" {
err := errors.New(events[0].Event.Error)
DefaultUi.Error(err.Error())
return err
}
if events[0].Event.Percentage == 100 {
return nil
}
time.Sleep(interval)
}
}