Skip to content

Commit

Permalink
Merge pull request #329 from askalik/feature-TopologyRequestCommand-U…
Browse files Browse the repository at this point in the history
…pdateRetriesCommand-with-retries

Feat(client/ C#): Update TopologyRequestCommand and UpdateRetriesCommand for retries
  • Loading branch information
ChrisKujawa authored Oct 6, 2021
2 parents 972ca7f + 2493fdd commit 4d0a8db
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 6 deletions.
15 changes: 15 additions & 0 deletions Client.UnitTests/TestDataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,21 @@ public static IEnumerable<TestCaseData> Provider()
}, new ActivateJobsResponse(),
(RequestCreator<IActivateJobsResponse>)
(zeebeClient => zeebeClient.NewActivateJobsCommand().JobType("type").MaxJobsToActivate(12)));
yield return new TestCaseData(
new TopologyRequest
{
ProcessInstanceKey = 12113
}, new TopologyResponse(),
(RequestCreator<ITopology>)
(zeebeClient => zeebeClient.TopologyRequest()));
yield return new TestCaseData(
new UpdateRetries
{
ProcessInstanceKey = 12113
}, new UpdateRetriesResponse()
{ RequestCreator<IUpdateRetries>}
(ZeebeClientTest => ZeebeClient.NewUpdateRetriesCommand()));
}

}
}
2 changes: 1 addition & 1 deletion Client/Api/Commands/ITopologyRequestStep1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

namespace Zeebe.Client.Api.Commands
{
public interface ITopologyRequestStep1 : IFinalCommandStep<ITopology>
public interface ITopologyRequestStep1 : IFinalCommandWithRetryStep<ITopology>
{
}
}
4 changes: 2 additions & 2 deletions Client/Api/Commands/IUpdateRetriesCommandStep1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public interface IUpdateRetriesCommandStep1
IUpdateRetriesCommandStep2 Retries(int retries);
}

public interface IUpdateRetriesCommandStep2 : IFinalCommandStep<IUpdateRetriesResponse>
public interface IUpdateRetriesCommandStep2 : IFinalCommandWithRetryStep<IUpdateRetriesResponse>
{
// the place for new optional parameters
// the place for new optional parameters
}
}
9 changes: 8 additions & 1 deletion Client/Impl/Commands/TopologyRequestCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ public class TopologyRequestCommand : ITopologyRequestStep1
{
private readonly Gateway.GatewayClient gatewayClient;
private readonly TopologyRequest request = new TopologyRequest();
private readonly IAsyncRetryStrategy asyncRetryStrategy;

public TopologyRequestCommand(Gateway.GatewayClient client)
public TopologyRequestCommand(Gateway.GatewayClient client, IAsyncRetryStrategy asyncRetryStrategy)
{

gatewayClient = client;
}

Expand All @@ -41,6 +43,11 @@ public async Task<ITopology> Send(TimeSpan? timeout = null, CancellationToken to
return new Topology(response);
}

public async Task<ITopology> SendWithRetry(TimeSpan? timespan = null, CancellationToken token = default)
{
return await asyncRetryStrategy.DoWithRetry(() => Send(timespan, token));
}

public async Task<ITopology> Send(CancellationToken cancellationToken)
{
return await Send(token: cancellationToken);
Expand Down
6 changes: 6 additions & 0 deletions Client/Impl/Commands/UpdateRetriesCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class UpdateRetriesCommand : IUpdateRetriesCommandStep1, IUpdateRetriesCo
{
private readonly UpdateJobRetriesRequest request;
private readonly Gateway.GatewayClient client;
private readonly IAsyncRetryStrategy asyncRetryStrategy;

public UpdateRetriesCommand(Gateway.GatewayClient client, long jobKey)
{
Expand Down Expand Up @@ -39,5 +40,10 @@ public async Task<IUpdateRetriesResponse> Send(CancellationToken cancellationTok
{
return await Send(token: cancellationToken);
}

public async Task<IUpdateRetriesResponse> SendWithRetry(CancellationToken cancellationToken)
{
return await asyncRetryStrategy.DoWithRetry(() => Send(token: cancellationToken));
}
}
}
4 changes: 2 additions & 2 deletions Client/ZeebeClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public IFailJobCommandStep1 NewFailCommand(long jobKey)

public IUpdateRetriesCommandStep1 NewUpdateRetriesCommand(long jobKey)
{
return new UpdateRetriesCommand(gatewayClient, jobKey);
return new UpdateRetriesCommand(gatewayClient, asyncRetryStrategy, jobKey);
}

public IThrowErrorCommandStep1 NewThrowErrorCommand(long jobKey)
Expand Down Expand Up @@ -164,7 +164,7 @@ public IPublishMessageCommandStep1 NewPublishMessageCommand()
return new PublishMessageCommand(gatewayClient);
}

public ITopologyRequestStep1 TopologyRequest() => new TopologyRequestCommand(gatewayClient);
public ITopologyRequestStep1 TopologyRequest() => new TopologyRequestCommand(gatewayClient, asyncRetryStrategy);

public void Dispose()
{
Expand Down

0 comments on commit 4d0a8db

Please sign in to comment.