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

Default request timeout #71

Merged
merged 1 commit into from
Nov 8, 2020
Merged
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
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