add gracefultimeout in server

This commit is contained in:
Денис Евстигнеев 2024-02-29 13:28:27 +03:00 committed by Vasiliy Tolstov
parent ccf92eb84d
commit d44a75d074
2 changed files with 16 additions and 0 deletions

View File

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

View File

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