Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions proximo/internal/proximoc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func consumeContext(ctx context.Context, proximoAddress string, consumer string,
case err := <-errs:
return err
case <-localCtx.Done():
return nil //ctx.Err()
return nil // ctx.Err()
}

}
Expand Down Expand Up @@ -197,7 +197,7 @@ func (p *ProducerConn) Close() error {

func (p *ProducerConn) start() error {

// defer p.stream.CloseSend()
// defer p.stream.CloseSend()

confirmations := make(chan *Confirmation, 16) // TODO: make buffer size configurable?

Expand Down Expand Up @@ -284,3 +284,8 @@ func makeId() string {
}
return base64.URLEncoding.EncodeToString(random)
}

// GrpcClient returns grpc client connection
func (p *ProducerConn) GrpcClient() *grpc.ClientConn {
return p.cc
}
2 changes: 1 addition & 1 deletion proximo/proximo_sink.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,5 @@ func (mq *messageSink) Close() error {

// Status reports the status of the message sink
func (mq *messageSink) Status() (*pubsub.Status, error) {
return nil, errors.New("status is not implemented")
return sinkStatus(mq.producer.GrpcClient())
}
41 changes: 41 additions & 0 deletions proximo/status.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package proximo

import (
"errors"

"github.com/utilitywarehouse/go-pubsub"
"google.golang.org/grpc"
"google.golang.org/grpc/connectivity"
)

// ErrNotConnected is returned if a status is requested before the connection has been initialized
var ErrNotConnected = errors.New("proximo not connected")

func sinkStatus(cc *grpc.ClientConn) (*pubsub.Status, error) {
if cc == nil {
return nil, ErrNotConnected
}

var working bool
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

	var (
		working bool
		problems []string
	)
	
	switch cc.GetState() {

looks better imho

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch

var problems []string
switch cc.GetState() {
case connectivity.Ready,
connectivity.Idle:
working = true
case connectivity.Shutdown,
connectivity.TransientFailure:
working = false
problems = append(problems, cc.GetState().String())
case connectivity.Connecting:
working = true
problems = append(problems, cc.GetState().String())
default:
working = false
problems = append(problems, "unknown connectivity state")
}

return &pubsub.Status{
Problems: problems,
Working: working,
}, nil
}