Skip to content

Commit

Permalink
fix: fix some chores
Browse files Browse the repository at this point in the history
  • Loading branch information
xjlgod committed Feb 27, 2024
1 parent 7d169e7 commit 8583d2f
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ require (
github.com/agiledragon/gomonkey v2.0.2+incompatible
github.com/agiledragon/gomonkey/v2 v2.9.0
github.com/mattn/go-sqlite3 v1.14.19
google.golang.org/protobuf v1.30.0
)

require (
Expand Down Expand Up @@ -86,7 +87,6 @@ require (
go.uber.org/multierr v1.8.0 // indirect
golang.org/x/arch v0.3.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/protobuf v1.30.0 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Expand Down
12 changes: 6 additions & 6 deletions pkg/saga/statemachine/engine/invoker/grpc_invoker.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,28 +217,28 @@ func (g *GPRCClientImpl) matchRetry(impl *state.ServiceTaskStateImpl, str string
}

func (g *GPRCClientImpl) needRetry(impl *state.ServiceTaskStateImpl, countMap map[state.Retry]int, retry state.Retry, err error) bool {
maxAttempt, exist := countMap[retry]
attempt, exist := countMap[retry]
if !exist {
countMap[retry] = 0
}

if maxAttempt >= retry.MaxAttempt() {
if attempt >= retry.MaxAttempt() {
return false
}

intervalSecond := retry.IntervalSecond()
backoffRate := retry.BackoffRate()
var currentInterval int64
if maxAttempt == 0 {
if attempt == 0 {
currentInterval = int64(intervalSecond * 1000)
} else {
currentInterval = int64(intervalSecond * backoffRate * float64(maxAttempt) * 1000)
currentInterval = int64(intervalSecond * backoffRate * float64(attempt) * 1000)
}

log.Warnf("invoke service[%s.%s] failed, will retry after %s millis, current retry count: %s, current err: %s",
impl.ServiceName(), impl.ServiceMethod(), currentInterval, maxAttempt, err)
impl.ServiceName(), impl.ServiceMethod(), currentInterval, attempt, err)

time.Sleep(time.Duration(currentInterval) * time.Millisecond)
countMap[retry] = maxAttempt + 1
countMap[retry] = attempt + 1
return true
}
2 changes: 1 addition & 1 deletion pkg/saga/statemachine/engine/invoker/grpc_invoker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func TestGRPCInvokerInvokeE2E(t *testing.T) {
go func() {
pb.StartProductServer()
}()
time.Sleep(3000)
time.Sleep(3000 * time.Millisecond)
conn, err := grpc.Dial("localhost:8080", grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
t.Fatalf("did not connect: %v", err)
Expand Down
2 changes: 0 additions & 2 deletions testdata/saga/engine/invoker/grpc/product.proto
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ option java_package = "io.grpc.examples.helloworld";
option java_outer_classname = "HelloWorldProto";

service ProductInfo {
//添加商品
rpc addProduct(Product) returns (ProductId);
//获取商品
rpc getProduct(ProductId) returns (Product);
}

Expand Down

0 comments on commit 8583d2f

Please sign in to comment.