Skip to content
This repository has been archived by the owner on Aug 12, 2020. It is now read-only.

Commit

Permalink
differentiate between api error and transport error
Browse files Browse the repository at this point in the history
  • Loading branch information
bradrydzewski committed Jun 29, 2017
1 parent 9685a43 commit edd4cda
Showing 1 changed file with 27 additions and 42 deletions.
69 changes: 27 additions & 42 deletions pipeline/rpc/client_grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ import (
"github.com/cncd/pipeline/pipeline/rpc/proto"

"google.golang.org/grpc"
"google.golang.org/grpc/codes"
)

var backoff = time.Second

type client struct {
client proto.DroneClient
conn *grpc.ClientConn
Expand Down Expand Up @@ -38,17 +41,13 @@ func (c *client) Next(ctx context.Context, f Filter) (*Pipeline, error) {
req.Filter.Labels = f.Labels
for {
res, err = c.client.Next(ctx, req)
//
// TODO error type
//
if err == nil {
break
}

println("error getting next execution. retry. " + err.Error())
select {
case <-time.After(1 * time.Second):
if grpc.Code(err) == codes.Unknown {
return nil, err
}
<-time.After(backoff)
}

if res.GetPipeline() == nil {
Expand All @@ -69,15 +68,13 @@ func (c *client) Wait(ctx context.Context, id string) (err error) {
req.Id = id
for {
_, err = c.client.Wait(ctx, req)
//
// TODO error type
//
if err == nil {
break
}
select {
case <-time.After(1 * time.Second):
if grpc.Code(err) == codes.Unknown {
return err
}
<-time.After(backoff)
}
return nil
}
Expand All @@ -95,15 +92,13 @@ func (c *client) Init(ctx context.Context, id string, state State) (err error) {
req.State.Name = state.Proc
for {
_, err = c.client.Init(ctx, req)
//
// TODO error type
//
if err == nil {
break
}
select {
case <-time.After(1 * time.Second):
if grpc.Code(err) == codes.Unknown {
return err
}
<-time.After(backoff)
}
return nil
}
Expand All @@ -121,15 +116,13 @@ func (c *client) Done(ctx context.Context, id string, state State) (err error) {
req.State.Name = state.Proc
for {
_, err = c.client.Done(ctx, req)
//
// TODO error type
//
if err == nil {
break
}
select {
case <-time.After(1 * time.Second):
if grpc.Code(err) == codes.Unknown {
return err
}
<-time.After(backoff)
}
return nil
}
Expand All @@ -140,15 +133,13 @@ func (c *client) Extend(ctx context.Context, id string) (err error) {
req.Id = id
for {
_, err = c.client.Extend(ctx, req)
//
// TODO error type
//
if err == nil {
break
}
select {
case <-time.After(1 * time.Second):
if grpc.Code(err) == codes.Unknown {
return err
}
<-time.After(backoff)
}
return nil
}
Expand All @@ -166,15 +157,13 @@ func (c *client) Update(ctx context.Context, id string, state State) (err error)
req.State.Name = state.Proc
for {
_, err = c.client.Update(ctx, req)
//
// TODO error type
//
if err == nil {
break
}
select {
case <-time.After(1 * time.Second):
if grpc.Code(err) == codes.Unknown {
return err
}
<-time.After(backoff)
}
return nil
}
Expand All @@ -192,15 +181,13 @@ func (c *client) Upload(ctx context.Context, id string, file *File) (err error)
req.File.Data = file.Data
for {
_, err = c.client.Upload(ctx, req)
//
// TODO error type
//
if err == nil {
break
}
select {
case <-time.After(1 * time.Second):
if grpc.Code(err) == codes.Unknown {
return err
}
<-time.After(backoff)
}
return nil
}
Expand All @@ -216,15 +203,13 @@ func (c *client) Log(ctx context.Context, id string, line *Line) (err error) {
req.Line.Time = line.Time
for {
_, err = c.client.Log(ctx, req)
//
// TODO error type
//
if err == nil {
break
}
select {
case <-time.After(1 * time.Second):
if grpc.Code(err) == codes.Unknown {
return err
}
<-time.After(backoff)
}
return nil
}

0 comments on commit edd4cda

Please sign in to comment.