add gracefultimeout in server
Some checks failed
lint / lint (pull_request) Has been cancelled
pr / test (pull_request) Has been cancelled

This commit is contained in:
Денис Евстигнеев 2024-02-29 13:28:27 +03:00
parent f06e0b21e8
commit bf0c3016cb
2 changed files with 11 additions and 0 deletions

View File

@ -65,6 +65,8 @@ type Options struct {
DeregisterAttempts int DeregisterAttempts int
// Hooks may contains HandleWrapper or Server func wrapper // Hooks may contains HandleWrapper or Server func wrapper
Hooks options.Hooks Hooks options.Hooks
// GracefulTimeout timeout for graceful stop server
GracefulTimeout time.Duration
} }
// NewOptions returns new options struct with default or passed values // NewOptions returns new options struct with default or passed values
@ -84,6 +86,7 @@ func NewOptions(opts ...options.Option) Options {
Name: DefaultName, Name: DefaultName,
Version: DefaultVersion, Version: DefaultVersion,
ID: id.Must(), ID: id.Must(),
GracefulTimeout: DefaultGracefulTimeout,
} }
for _, o := range opts { for _, o := range opts {
@ -162,6 +165,12 @@ func Listener(nl net.Listener) options.Option {
} }
} }
func GracefulTimeout(t time.Duration) options.Option {
return func(src interface{}) error {
return options.Set(src, t, ".GracefulTimeout")
}
}
// HandleOptions struct // HandleOptions struct
type HandleOptions struct { type HandleOptions struct {
// Context holds external options // Context holds external options

View File

@ -32,6 +32,8 @@ var (
DefaultMaxMsgRecvSize = 1024 * 1024 * 4 // 4Mb DefaultMaxMsgRecvSize = 1024 * 1024 * 4 // 4Mb
// DefaultMaxMsgSendSize holds default max send size // DefaultMaxMsgSendSize holds default max send size
DefaultMaxMsgSendSize = 1024 * 1024 * 4 // 4Mb DefaultMaxMsgSendSize = 1024 * 1024 * 4 // 4Mb
// DefaultGracefulTimeout default time for graceful stop
DefaultGracefulTimeout = 5 * time.Second
) )
// Server is a simple micro server abstraction // Server is a simple micro server abstraction