mirror of
https://github.com/kemko/nomad.git
synced 2026-01-01 16:05:42 +03:00
logmon client to handle grpc closing errors
This commit is contained in:
@@ -4,10 +4,14 @@ import (
|
||||
"context"
|
||||
|
||||
"github.com/hashicorp/nomad/client/logmon/proto"
|
||||
"github.com/hashicorp/nomad/helper/pluginutils/grpcutils"
|
||||
)
|
||||
|
||||
type logmonClient struct {
|
||||
client proto.LogMonClient
|
||||
|
||||
// doneCtx is closed when the plugin exits
|
||||
doneCtx context.Context
|
||||
}
|
||||
|
||||
func (c *logmonClient) Start(cfg *LogConfig) error {
|
||||
@@ -21,11 +25,11 @@ func (c *logmonClient) Start(cfg *LogConfig) error {
|
||||
StderrFifo: cfg.StderrFifo,
|
||||
}
|
||||
_, err := c.client.Start(context.Background(), req)
|
||||
return err
|
||||
return grpcutils.HandleGrpcErr(err, c.doneCtx)
|
||||
}
|
||||
|
||||
func (c *logmonClient) Stop() error {
|
||||
req := &proto.StopRequest{}
|
||||
_, err := c.client.Stop(context.Background(), req)
|
||||
return err
|
||||
return grpcutils.HandleGrpcErr(err, c.doneCtx)
|
||||
}
|
||||
|
||||
@@ -73,5 +73,8 @@ func (p *Plugin) GRPCServer(broker *plugin.GRPCBroker, s *grpc.Server) error {
|
||||
}
|
||||
|
||||
func (p *Plugin) GRPCClient(ctx context.Context, broker *plugin.GRPCBroker, c *grpc.ClientConn) (interface{}, error) {
|
||||
return &logmonClient{client: proto.NewLogMonClient(c)}, nil
|
||||
return &logmonClient{
|
||||
doneCtx: ctx,
|
||||
client: proto.NewLogMonClient(c),
|
||||
}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user