From d44a75d07494f983bd503f7f1b26be3241addc65 Mon Sep 17 00:00:00 2001 From: Evstigneev Denis Date: Thu, 29 Feb 2024 13:28:27 +0300 Subject: [PATCH] add gracefultimeout in server --- server/options.go | 14 ++++++++++++++ server/server.go | 2 ++ 2 files changed, 16 insertions(+) diff --git a/server/options.go b/server/options.go index 8ab8c0d2..45f9a612 100644 --- a/server/options.go +++ b/server/options.go @@ -86,6 +86,8 @@ type Options struct { DeregisterAttempts int // Hooks may contains SubscriberWrapper, HandlerWrapper or Server func wrapper Hooks options.Hooks + // GracefulTimeout timeout for graceful stop server + GracefulTimeout time.Duration } // NewOptions returns new options struct with default or passed values @@ -108,6 +110,7 @@ func NewOptions(opts ...Option) Options { Version: DefaultVersion, ID: id.Must(), Namespace: DefaultNamespace, + GracefulTimeout: DefaultGracefulTimeout, } for _, o := range opts { @@ -318,11 +321,22 @@ func Listener(l net.Listener) Option { } } +<<<<<<< HEAD // HandlerOption func type HandlerOption func(*HandlerOptions) // HandlerOptions struct type HandlerOptions struct { +======= +func GracefulTimeout(t time.Duration) options.Option { + return func(src interface{}) error { + return options.Set(src, t, ".GracefulTimeout") + } +} + +// HandleOptions struct +type HandleOptions struct { +>>>>>>> bf0c3016cb09 (add gracefultimeout in server) // Context holds external options Context context.Context // Metadata for handler diff --git a/server/server.go b/server/server.go index ef710d79..e38d06e8 100644 --- a/server/server.go +++ b/server/server.go @@ -34,6 +34,8 @@ var ( DefaultMaxMsgRecvSize = 1024 * 1024 * 4 // 4Mb // DefaultMaxMsgSendSize holds default max send size DefaultMaxMsgSendSize = 1024 * 1024 * 4 // 4Mb + // DefaultGracefulTimeout default time for graceful stop + DefaultGracefulTimeout = 5 * time.Second ) // Server is a simple micro server abstraction