Skip to content
This repository has been archived by the owner on May 8, 2024. It is now read-only.

Commit

Permalink
Default request timeout (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
fkorotkov committed Nov 8, 2020
1 parent f0ea66a commit 8be8377
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions cmd/agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/cirruslabs/cirrus-ci-agent/internal/network"
"github.com/grpc-ecosystem/go-grpc-middleware/retry"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/credentials"
"google.golang.org/grpc/grpclog"
"io"
Expand Down Expand Up @@ -173,6 +174,9 @@ func dialWithTimeout(apiEndpoint string) (*grpc.ClientConn, error) {
if insecure {
transportSecurity = grpc.WithInsecure()
}
retryCodes := []codes.Code{
codes.Unavailable, codes.Internal, codes.Unknown, codes.ResourceExhausted, codes.DeadlineExceeded,
}
return grpc.DialContext(
ctx,
target,
Expand All @@ -181,6 +185,8 @@ func dialWithTimeout(apiEndpoint string) (*grpc.ClientConn, error) {
grpc.WithUnaryInterceptor(
grpc_retry.UnaryClientInterceptor(
grpc_retry.WithMax(3),
grpc_retry.WithCodes(retryCodes...),
grpc_retry.WithPerRetryTimeout(10*time.Second),
),
),
)
Expand Down Expand Up @@ -217,6 +223,7 @@ func sendHeartbeat(taskId int64, clientToken string) {
TaskId: taskId,
Secret: clientToken,
}
log.Println("Sending heartbeat...")
_, err := client.CirrusClient.Heartbeat(context.Background(), &api.HeartbeatRequest{TaskIdentification: &taskIdentification})
if err != nil {
log.Printf("Failed to send heartbeat: %v", err)
Expand Down

0 comments on commit 8be8377

Please sign in to comment.