Set register ttl/interval by default for functions since they are more ephemeral
This commit is contained in:
parent
1932bc805b
commit
eecf26619b
18
function.go
18
function.go
@ -1,6 +1,8 @@
|
|||||||
package micro
|
package micro
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/micro/go-micro/server"
|
"github.com/micro/go-micro/server"
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
)
|
)
|
||||||
@ -30,8 +32,20 @@ func fnSubWrapper(f Function) server.SubscriberWrapper {
|
|||||||
|
|
||||||
func newFunction(opts ...Option) Function {
|
func newFunction(opts ...Option) Function {
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
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{
|
fn := &function{
|
||||||
cancel: cancel,
|
cancel: cancel,
|
||||||
|
Loading…
Reference in New Issue
Block a user