Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Stop() for uber/fx hook #5

Merged
merged 1 commit into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 9 additions & 1 deletion server/grpc/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package grpc
import (
"net"

"github.com/asim/emque/proto"
mq "github.com/asim/emque/proto"
"github.com/asim/emque/server"
"github.com/asim/emque/server/util"
"google.golang.org/grpc"
Expand All @@ -12,6 +12,7 @@ import (

type grpcServer struct {
options *server.Options
srv *grpc.Server
}

func (g *grpcServer) Run() error {
Expand Down Expand Up @@ -50,6 +51,7 @@ func (g *grpcServer) Run() error {

// new grpc server
srv := grpc.NewServer(opts...)
g.srv = srv

// register MQ server
mq.RegisterMQServer(srv, new(handler))
Expand All @@ -58,6 +60,12 @@ func (g *grpcServer) Run() error {
return srv.Serve(l)
}

func (g *grpcServer) Stop() error {
g.srv.GracefulStop()
return nil

}

func New(opts ...server.Option) *grpcServer {
options := new(server.Options)
for _, o := range opts {
Expand Down
8 changes: 8 additions & 0 deletions server/http/http.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package http

import (
"context"
"crypto/tls"
"net/http"
"os"
Expand All @@ -12,6 +13,7 @@ import (

type httpServer struct {
options *server.Options
srv *http.Server
}

func (h *httpServer) Run() error {
Expand Down Expand Up @@ -58,9 +60,15 @@ func (h *httpServer) Run() error {
TLSConfig: config,
}

h.srv = srv

return srv.Serve(l)
}

func (h *httpServer) Stop() error {
return h.srv.Shutdown(context.TODO())
}

func New(opts ...server.Option) *httpServer {
options := new(server.Options)
for _, o := range opts {
Expand Down
1 change: 1 addition & 0 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ package server

type Server interface {
Run() error
Stop() error
}