Skip to content

Commit

Permalink
Merge pull request #13 from bavix/dev
Browse files Browse the repository at this point in the history
add new values for keepalive
  • Loading branch information
rez1dent3 authored Aug 21, 2024
2 parents 2491a50 + e1ba59f commit 18c7f08
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 5 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
go-version: [ '1.22' ]
go-version: [ '1.23' ]
steps:
- uses: actions/checkout@v4
- name: Setup Go
Expand All @@ -23,4 +23,4 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.59.1
version: v1.60.1
2 changes: 1 addition & 1 deletion .github/workflows/unit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
go-version: [ '1.22' ]
go-version: [ '1.23' ]
steps:
- uses: actions/checkout@v4
- name: Setup Go
Expand Down
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
run:
go: "1.23"
timeout: 1m
linters:
enable-all: true
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ test:
go test -tags mock -race -cover ./...

lint:
go run github.com/golangci/golangci-lint/cmd/golangci-lint@v1.59.1 run --color always ${args}
go run github.com/golangci/golangci-lint/cmd/golangci-lint@v1.60.1 run --color always ${args}

lint-fix:
make lint args=--fix
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/bavix/vakeel

go 1.22.5
go 1.23

require (
github.com/bavix/apis v1.0.0
Expand Down
25 changes: 25 additions & 0 deletions internal/build/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,47 @@ import (
"context"
"net"
"strconv"
"time"

"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/keepalive"

"github.com/bavix/vakeel-way/pkg/api/vakeel_way"
"github.com/bavix/vakeel/internal/app"
"github.com/bavix/vakeel/internal/infra/templater"
"github.com/bavix/vakeel/pkg/ctxid"
)

// Keep-alive parameters for the gRPC client.
// The client will send a ping to the server every 10 seconds if there is no activity.
// The client will consider the connection dead if it doesn't receive a pong within 1 second.
// The client will allow the connection to be established without a stream.
const (
keepAliveTime = 10 * time.Second // The time between pings.
keepAliveTimeout = 1 * time.Second // The time to wait for a pong.
allowWithoutStreams = true // Allow the connection to be established without a stream.
)

// AgentApp creates a gRPC client and connects to the server's update service.
// It returns an error if the connection or the update service call fails.
//
// ctx: The context.Context to use for the gRPC call.
// Returns: An error if the connection or update service call fails.
func (b *Builder) AgentApp(ctx context.Context) error {
// Create a gRPC client insecure connection to the server.
// The connection is established using the host and port from the configuration.
// The connection is configured with keep-alive parameters to send pings to the server
// every 10 seconds if there is no activity and to consider the connection dead if
// a ping ack is not received within 1 second.
conn, err := grpc.NewClient(
net.JoinHostPort(b.config.Host, strconv.Itoa(b.config.Port)),
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithKeepaliveParams(keepalive.ClientParameters{
Time: keepAliveTime,
Timeout: keepAliveTimeout,
PermitWithoutStream: allowWithoutStreams,
}),
)
if err != nil {
return err
Expand All @@ -32,8 +53,12 @@ func (b *Builder) AgentApp(ctx context.Context) error {
// Close the connection when the function returns.
defer conn.Close()

// Create a client for the vakeel_way.StateService.
serviceClient := vakeel_way.NewStateServiceClient(conn)

// Call the app.Agent function to start the agent.
// The agent sends update requests to the server using the client stream.
// The function returns an error if sending the update request fails.
return app.Agent(ctx, serviceClient)
}

Expand Down

0 comments on commit 18c7f08

Please sign in to comment.