From eecf26619bdf809bf650acb3cf57045e7f4ef927 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Thu, 1 Jun 2017 12:44:18 +0100 Subject: [PATCH] Set register ttl/interval by default for functions since they are more ephemeral --- function.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/function.go b/function.go index 631c04ac..bc47d38f 100644 --- a/function.go +++ b/function.go @@ -1,6 +1,8 @@ package micro import ( + "time" + "github.com/micro/go-micro/server" "golang.org/x/net/context" ) @@ -30,8 +32,20 @@ func fnSubWrapper(f Function) server.SubscriberWrapper { func newFunction(opts ...Option) Function { ctx, cancel := context.WithCancel(context.Background()) - opts = append(opts, Context(ctx)) - service := newService(opts...) + + // force ttl/interval + fopts := []Option{ + RegisterTTL(time.Minute), + RegisterInterval(time.Second * 30), + } + + // prepend to opts + fopts = append(fopts, opts...) + + // make context the last thing + fopts = append(fopts, Context(ctx)) + + service := newService(fopts...) fn := &function{ cancel: cancel,