Set register ttl/interval by default for functions since they are more ephemeral

This commit is contained in:
Asim Aslam 2017-06-01 12:44:18 +01:00
parent 1932bc805b
commit eecf26619b

View File

@ -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,