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

Adds Statuser implementation #88

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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())
}
43 changes: 43 additions & 0 deletions proximo/status.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
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
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
}