本文整理匯總了Golang中github.com/coreos/fleet/registry.Registry.LeaseRole方法的典型用法代碼示例。如果您正苦於以下問題:Golang Registry.LeaseRole方法的具體用法?Golang Registry.LeaseRole怎麽用?Golang Registry.LeaseRole使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/coreos/fleet/registry.Registry
的用法示例。
在下文中一共展示了Registry.LeaseRole方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: ensureLeader
// ensureLeader will attempt to renew a non-nil Lease, falling back to
// acquiring a new Lease on the lead engine role.
func ensureLeader(prev registry.Lease, reg registry.Registry, machID string) (cur registry.Lease) {
if prev != nil {
err := prev.Renew(engineRoleLeasePeriod)
if err == nil {
cur = prev
return
} else {
log.Errorf("Engine leadership could not be renewed: %v", err)
}
}
var err error
cur, err = reg.LeaseRole(engineRoleName, machID, engineRoleLeasePeriod)
if err != nil {
log.Errorf("Failed acquiring engine leadership: %v", err)
} else if cur == nil {
log.V(1).Infof("Unable to acquire engine leadership")
} else {
log.Infof("Acquired engine leadership")
}
return
}
示例2: ensureLeader
// ensureLeader will attempt to renew a non-nil Lease, falling back to
// acquiring a new Lease on the lead engine role.
func ensureLeader(prev registry.Lease, reg registry.Registry, machID string, ttl time.Duration) (cur registry.Lease) {
if prev != nil {
err := prev.Renew(ttl)
if err == nil {
log.V(1).Infof("Engine leadership renewed")
cur = prev
return
} else {
log.Errorf("Engine leadership lost, renewal failed: %v", err)
}
}
var err error
cur, err = reg.LeaseRole(engineRoleName, machID, ttl)
if err != nil {
log.Errorf("Engine leadership acquisition failed: %v", err)
} else if cur == nil {
log.V(1).Infof("Unable to acquire engine leadership")
} else {
log.Infof("Engine leadership acquired")
}
return
}