Merge pull request 'server: add GracefulTimeout option' (#304) from graceful into v3

Reviewed-on: #304
This commit is contained in:
Василий Толстов 2024-02-29 23:24:43 +03:00
commit 2d5acaca2f
5 changed files with 22 additions and 9 deletions

View File

@ -10,11 +10,11 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: setup-go - name: setup-go
uses: https://gitea.com/actions/setup-go@v3 uses: actions/setup-go@v3
with: with:
go-version: 1.18 go-version: 1.21
- name: checkout - name: checkout
uses: https://gitea.com/actions/checkout@v3 uses: actions/checkout@v3
- name: deps - name: deps
run: go get -v -d ./... run: go get -v -d ./...
- name: lint - name: lint

View File

@ -10,11 +10,11 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: checkout - name: checkout
uses: https://gitea.com/actions/checkout@v3 uses: actions/checkout@v3
- name: setup-go - name: setup-go
uses: https://gitea.com/actions/setup-go@v3 uses: actions/setup-go@v3
with: with:
go-version: 1.18 go-version: 1.21
- name: deps - name: deps
run: go get -v -t -d ./... run: go get -v -t -d ./...
- name: test - name: test

2
go.mod
View File

@ -1,6 +1,6 @@
module go.unistack.org/micro/v3 module go.unistack.org/micro/v3
go 1.19 go 1.20
require ( require (
github.com/DATA-DOG/go-sqlmock v1.5.0 github.com/DATA-DOG/go-sqlmock v1.5.0

View File

@ -86,6 +86,8 @@ type Options struct {
DeregisterAttempts int DeregisterAttempts int
// Hooks may contains SubscriberWrapper, HandlerWrapper or Server func wrapper // Hooks may contains SubscriberWrapper, HandlerWrapper 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
@ -108,6 +110,7 @@ func NewOptions(opts ...Option) Options {
Version: DefaultVersion, Version: DefaultVersion,
ID: id.Must(), ID: id.Must(),
Namespace: DefaultNamespace, Namespace: DefaultNamespace,
GracefulTimeout: DefaultGracefulTimeout,
} }
for _, o := range opts { for _, o := range opts {
@ -321,6 +324,14 @@ func Listener(l net.Listener) Option {
// HandlerOption func // HandlerOption func
type HandlerOption func(*HandlerOptions) type HandlerOption func(*HandlerOptions)
// GracefulTimeout duration
func GracefulTimeout(td time.Duration) Option {
return func(o *Options) {
o.GracefulTimeout = td
}
}
// HandlerOptions struct // HandlerOptions struct
type HandlerOptions struct { type HandlerOptions struct {
// Context holds external options // Context holds external options

View File

@ -34,6 +34,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