From d44a75d07494f983bd503f7f1b26be3241addc65 Mon Sep 17 00:00:00 2001 From: Evstigneev Denis Date: Thu, 29 Feb 2024 13:28:27 +0300 Subject: [PATCH 1/5] add gracefultimeout in server --- server/options.go | 14 ++++++++++++++ server/server.go | 2 ++ 2 files changed, 16 insertions(+) diff --git a/server/options.go b/server/options.go index 8ab8c0d2..45f9a612 100644 --- a/server/options.go +++ b/server/options.go @@ -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 diff --git a/server/server.go b/server/server.go index ef710d79..e38d06e8 100644 --- a/server/server.go +++ b/server/server.go @@ -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 From 0459ea0613112bf8f4df850b0a68c8030335eb20 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Thu, 29 Feb 2024 22:40:05 +0300 Subject: [PATCH 2/5] fixup Signed-off-by: Vasiliy Tolstov --- server/options.go | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/server/options.go b/server/options.go index 45f9a612..32a5f60d 100644 --- a/server/options.go +++ b/server/options.go @@ -321,22 +321,19 @@ 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") +// GracefulTimeout duration +func GracefulTimeout(td time.Duration) options.Option { + return func(o *Options) { + o.GracefulTimeout = td } } -// HandleOptions struct -type HandleOptions struct { ->>>>>>> bf0c3016cb09 (add gracefultimeout in server) + +// HandlerOptions struct +type HandlerOptions struct { // Context holds external options Context context.Context // Metadata for handler From e87ff942bb07026ba44fb9952e9b61f02642db53 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Thu, 29 Feb 2024 23:03:39 +0300 Subject: [PATCH 3/5] bump gomod Signed-off-by: Vasiliy Tolstov --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 65e6a1f5..a16001cb 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module go.unistack.org/micro/v3 -go 1.19 +go 1.20 require ( github.com/DATA-DOG/go-sqlmock v1.5.0 From 2c282825ce223ad04cce344426159974bce2ac26 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Thu, 29 Feb 2024 23:17:36 +0300 Subject: [PATCH 4/5] fixup Signed-off-by: Vasiliy Tolstov --- server/options.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/options.go b/server/options.go index 32a5f60d..e6754992 100644 --- a/server/options.go +++ b/server/options.go @@ -325,7 +325,7 @@ func Listener(l net.Listener) Option { type HandlerOption func(*HandlerOptions) // GracefulTimeout duration -func GracefulTimeout(td time.Duration) options.Option { +func GracefulTimeout(td time.Duration) Option { return func(o *Options) { o.GracefulTimeout = td } From 0674df3d9f5e914d2e94b68b9e5d86945deb975e Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Thu, 29 Feb 2024 23:23:51 +0300 Subject: [PATCH 5/5] update workflow Signed-off-by: Vasiliy Tolstov --- .gitea/workflows/lint.yml | 8 ++++---- .gitea/workflows/pr.yml | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.gitea/workflows/lint.yml b/.gitea/workflows/lint.yml index 8da88945..1cc293dc 100644 --- a/.gitea/workflows/lint.yml +++ b/.gitea/workflows/lint.yml @@ -10,15 +10,15 @@ jobs: runs-on: ubuntu-latest steps: - name: setup-go - uses: https://gitea.com/actions/setup-go@v3 + uses: actions/setup-go@v3 with: - go-version: 1.18 + go-version: 1.21 - name: checkout - uses: https://gitea.com/actions/checkout@v3 + uses: actions/checkout@v3 - name: deps run: go get -v -d ./... - name: lint uses: https://github.com/golangci/golangci-lint-action@v3.4.0 continue-on-error: true with: - version: v1.52 \ No newline at end of file + version: v1.52 diff --git a/.gitea/workflows/pr.yml b/.gitea/workflows/pr.yml index ba947f0c..b3e67b06 100644 --- a/.gitea/workflows/pr.yml +++ b/.gitea/workflows/pr.yml @@ -10,14 +10,14 @@ jobs: runs-on: ubuntu-latest steps: - name: checkout - uses: https://gitea.com/actions/checkout@v3 + uses: actions/checkout@v3 - name: setup-go - uses: https://gitea.com/actions/setup-go@v3 + uses: actions/setup-go@v3 with: - go-version: 1.18 + go-version: 1.21 - name: deps run: go get -v -t -d ./... - name: test env: INTEGRATION_TESTS: yes - run: go test -mod readonly -v ./... \ No newline at end of file + run: go test -mod readonly -v ./...