add gracefultimeout in server #303

Merged
vtolstov merged 1 commits from devstigneev/micro:issue_293 into master 2024-02-29 22:31:50 +03:00
2 changed files with 11 additions and 0 deletions
Showing only changes of commit bf0c3016cb - Show all commits

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