server: add GracefulTimeout option #304

Merged
vtolstov merged 5 commits from graceful into v3 2024-02-29 23:24:52 +03:00
2 changed files with 16 additions and 0 deletions
Showing only changes of commit d44a75d074 - Show all commits

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