From 32a2005f6d146581775ef08e7863421db5ee38ab Mon Sep 17 00:00:00 2001 From: shikbupt Date: Fri, 10 Jan 2020 22:25:28 +0800 Subject: [PATCH 1/2] add option for web service signal handler (#1091) --- web/options.go | 12 ++++++++++++ web/service.go | 4 +++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/web/options.go b/web/options.go index 03e23484..0570f7ba 100644 --- a/web/options.go +++ b/web/options.go @@ -46,6 +46,8 @@ type Options struct { // Static directory StaticDir string + + Signal bool } func newOptions(opts ...Option) Options { @@ -59,6 +61,7 @@ func newOptions(opts ...Option) Options { StaticDir: DefaultStaticDir, Service: micro.NewService(), Context: context.TODO(), + Signal: true, } for _, o := range opts { @@ -242,3 +245,12 @@ func RegisterCheck(fn func(context.Context) error) Option { o.RegisterCheck = fn } } + +// HandleSignal toggles automatic installation of the signal handler that +// traps TERM, INT, and QUIT. Users of this feature to disable the signal +// handler, should control liveness of the service through the context. +func HandleSignal(b bool) Option { + return func(o *Options) { + o.Signal = b + } +} diff --git a/web/service.go b/web/service.go index e9d6801b..b76b13b9 100644 --- a/web/service.go +++ b/web/service.go @@ -383,7 +383,9 @@ func (s *service) Run() error { go s.run(ex) ch := make(chan os.Signal, 1) - signal.Notify(ch, syscall.SIGTERM, syscall.SIGINT) + if s.opts.Signal { + signal.Notify(ch, syscall.SIGTERM, syscall.SIGINT) + } select { // wait on kill signal From f4fb923fb2705b31a860fcb56f63ae30a450a50d Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Fri, 10 Jan 2020 18:04:15 +0300 Subject: [PATCH 2/2] pass additional context for broker subscribe (#1105) Signed-off-by: Vasiliy Tolstov --- server/grpc/grpc.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/server/grpc/grpc.go b/server/grpc/grpc.go index 874f7273..d2655a95 100644 --- a/server/grpc/grpc.go +++ b/server/grpc/grpc.go @@ -645,6 +645,10 @@ func (g *grpcServer) Register() error { opts = append(opts, broker.Queue(queue)) } + if cx := sb.Options().Context; cx != nil { + opts = append(opts, broker.SubscribeContext(cx)) + } + if !sb.Options().AutoAck { opts = append(opts, broker.DisableAutoAck()) }