Merge pull request #778 from micro/register-interval
Set register ttl and interval by default
This commit is contained in:
commit
71ab35e055
@ -95,11 +95,13 @@ var (
|
|||||||
cli.IntFlag{
|
cli.IntFlag{
|
||||||
Name: "register_ttl",
|
Name: "register_ttl",
|
||||||
EnvVar: "MICRO_REGISTER_TTL",
|
EnvVar: "MICRO_REGISTER_TTL",
|
||||||
|
Value: 60,
|
||||||
Usage: "Register TTL in seconds",
|
Usage: "Register TTL in seconds",
|
||||||
},
|
},
|
||||||
cli.IntFlag{
|
cli.IntFlag{
|
||||||
Name: "register_interval",
|
Name: "register_interval",
|
||||||
EnvVar: "MICRO_REGISTER_INTERVAL",
|
EnvVar: "MICRO_REGISTER_INTERVAL",
|
||||||
|
Value: 30,
|
||||||
Usage: "Register interval in seconds",
|
Usage: "Register interval in seconds",
|
||||||
},
|
},
|
||||||
cli.StringFlag{
|
cli.StringFlag{
|
||||||
@ -417,11 +419,11 @@ func (c *cmd) Before(ctx *cli.Context) error {
|
|||||||
serverOpts = append(serverOpts, server.Advertise(ctx.String("server_advertise")))
|
serverOpts = append(serverOpts, server.Advertise(ctx.String("server_advertise")))
|
||||||
}
|
}
|
||||||
|
|
||||||
if ttl := time.Duration(ctx.GlobalInt("register_ttl")); ttl > 0 {
|
if ttl := time.Duration(ctx.GlobalInt("register_ttl")); ttl >= 0 {
|
||||||
serverOpts = append(serverOpts, server.RegisterTTL(ttl*time.Second))
|
serverOpts = append(serverOpts, server.RegisterTTL(ttl*time.Second))
|
||||||
}
|
}
|
||||||
|
|
||||||
if val := time.Duration(ctx.GlobalInt("register_interval")); val > 0 {
|
if val := time.Duration(ctx.GlobalInt("register_interval")); val >= 0 {
|
||||||
serverOpts = append(serverOpts, server.RegisterInterval(val*time.Second))
|
serverOpts = append(serverOpts, server.RegisterInterval(val*time.Second))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,6 +44,8 @@ func newOptions(opt ...Option) Options {
|
|||||||
opts := Options{
|
opts := Options{
|
||||||
Codecs: make(map[string]codec.NewCodec),
|
Codecs: make(map[string]codec.NewCodec),
|
||||||
Metadata: map[string]string{},
|
Metadata: map[string]string{},
|
||||||
|
RegisterInterval: DefaultRegisterInterval,
|
||||||
|
RegisterTTL: DefaultRegisterTTL,
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, o := range opt {
|
for _, o := range opt {
|
||||||
|
@ -123,6 +123,8 @@ var (
|
|||||||
DefaultServer Server = newRpcServer()
|
DefaultServer Server = newRpcServer()
|
||||||
DefaultRouter = newRpcRouter()
|
DefaultRouter = newRpcRouter()
|
||||||
DefaultRegisterCheck = func(context.Context) error { return nil }
|
DefaultRegisterCheck = func(context.Context) error { return nil }
|
||||||
|
DefaultRegisterInterval = time.Second * 30
|
||||||
|
DefaultRegisterTTL = time.Minute
|
||||||
)
|
)
|
||||||
|
|
||||||
// DefaultOptions returns config options for the default service
|
// DefaultOptions returns config options for the default service
|
||||||
|
Loading…
Reference in New Issue
Block a user