Merge pull request 'add gracefultimeout in server' (#303) from devstigneev/micro:issue_293 into master
Some checks failed
/ autoupdate (push) Failing after 1m5s
Some checks failed
/ autoupdate (push) Failing after 1m5s
Reviewed-on: #303
This commit is contained in:
commit
de83f42149
@ -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
|
||||||
|
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user