Skip to content

Commit

Permalink
feat: saga support retrylimit (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
catcherwong authored Aug 30, 2022
1 parent 6b3602f commit 7b9deac
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion build/version.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>
<PropertyGroup>

<DtmCSharpVersion>1.2.0</DtmCSharpVersion>
<DtmCSharpVersion>1.3.0</DtmCSharpVersion>

</PropertyGroup>
</Project>
6 changes: 6 additions & 0 deletions src/DtmCommon/Imp/TransBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ public class TransBase
[JsonPropertyName("branch_headers")]
public Dictionary<string, string> BranchHeaders { get; set; }

[JsonPropertyName("retry_limit")]
public long RetryLimit { get; set; }

[JsonPropertyName("retry_count")]
public long RetryCount { get; set; }

/// <summary>
/// use in MSG/SAGA
/// </summary>
Expand Down
11 changes: 11 additions & 0 deletions src/Dtmcli/Saga/Saga.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,16 @@ public Saga SetBranchHeaders(Dictionary<string, string> headers)
this._transBase.BranchHeaders = headers;
return this;
}

/// <summary>
/// Set global trans retry limit
/// </summary>
/// <param name="limit"></param>
/// <returns></returns>
public Saga SetRetryLimit(long limit)
{
this._transBase.RetryLimit = limit;
return this;
}
}
}
1 change: 1 addition & 0 deletions src/Dtmgrpc/DtmgRPCClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ private dtmgpb.DtmRequest BuildDtmRequest(TransBase transBase)
WaitResult = transBase.WaitResult,
TimeoutToFail = transBase.TimeoutToFail,
RetryInterval = transBase.RetryInterval,
RetryLimit = transBase.RetryLimit,
};

if (transBase.BranchHeaders != null)
Expand Down
11 changes: 11 additions & 0 deletions src/Dtmgrpc/Saga/SagaGrpc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,16 @@ public SagaGrpc SetBranchHeaders(Dictionary<string, string> headers)
this._transBase.BranchHeaders = headers;
return this;
}

/// <summary>
/// Set global trans retry limit
/// </summary>
/// <param name="limit"></param>
/// <returns></returns>
public SagaGrpc SetRetryLimit(long limit)
{
this._transBase.RetryLimit = limit;
return this;
}
}
}
2 changes: 2 additions & 0 deletions src/Dtmgrpc/dtmgpb/dtmgimp.proto
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ message DtmTransOptions {
int64 RetryInterval = 3;
// repeated string PassthroughHeaders = 4;
map<string, string> BranchHeaders = 5;
int64 RequestTimeout = 6;
int64 RetryLimit = 7;
}

// DtmRequest request sent to dtm server
Expand Down
2 changes: 2 additions & 0 deletions tests/Dtmcli.Tests/SagaTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public async void Submit_Should_Succeed()
.EnableWaitResult()
.SetRetryInterval(10)
.SetTimeoutToFail(100)
.SetRetryLimit(2)
.SetBranchHeaders(new Dictionary<string, string>
{
{ "bh1", "123" },
Expand Down Expand Up @@ -123,6 +124,7 @@ protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage
Assert.Contains("bh2", transBase.BranchHeaders.Keys);
Assert.Equal(4, transBase.Payloads.Count);
Assert.Equal(4, transBase.Steps.Count);
Assert.Equal(2, transBase.RetryLimit);

var content = new StringContent("{\"dtm_result\":\"SUCCESS\"}");

Expand Down
2 changes: 2 additions & 0 deletions tests/Dtmgrpc.Tests/SagaTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public async void Submit_Should_Succeed()
.EnableConcurrent()
.SetRetryInterval(10)
.SetTimeoutToFail(100)
.SetRetryLimit(2)
.SetBranchHeaders(new Dictionary<string, string>
{
{ "bh1", "123" },
Expand All @@ -43,6 +44,7 @@ public async void Submit_Should_Succeed()
Assert.NotNull(tb.CustomData);
Assert.Equal(10, tb.RetryInterval);
Assert.Equal(100, tb.TimeoutToFail);
Assert.Equal(2, tb.RetryLimit);

Assert.True(true);
}
Expand Down

0 comments on commit 7b9deac

Please sign in to comment.