server: add GracefulTimeout option #304
@ -10,15 +10,15 @@ 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
|
||||||
uses: https://github.com/golangci/golangci-lint-action@v3.4.0
|
uses: https://github.com/golangci/golangci-lint-action@v3.4.0
|
||||||
continue-on-error: true
|
continue-on-error: true
|
||||||
with:
|
with:
|
||||||
version: v1.52
|
version: v1.52
|
||||||
|
@ -10,14 +10,14 @@ 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
|
||||||
env:
|
env:
|
||||||
INTEGRATION_TESTS: yes
|
INTEGRATION_TESTS: yes
|
||||||
run: go test -mod readonly -v ./...
|
run: go test -mod readonly -v ./...
|
||||||
|
2
go.mod
2
go.mod
@ -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
|
||||||
|
@ -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
|
||||||
|
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user