-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implementation of UpdateJobTimeoutCommand #682
Merged
ChrisKujawa
merged 6 commits into
camunda-community-hub:main
from
LennartKleymann:681-add-update-job-timeout-command
May 27, 2024
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
29d0799
feat: added implementation for the UpdateJobTimeoutCommand
LennartKleymann 7b69dc7
test: added unit test for the UpdateJobTimeoutCommand
LennartKleymann e27a873
docs: clarify comment
ChrisKujawa 2bf0491
docs: clarify comment
ChrisKujawa 0b294e0
fix: convert timeout to long to align with Zeebe gateway protocol
LennartKleymann 87e1684
test: added unit test to check expected requests for UpdateJobTimeout…
LennartKleymann File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using GatewayProtocol; | ||
using Grpc.Core; | ||
using NUnit.Framework; | ||
|
||
namespace Zeebe.Client; | ||
|
||
[TestFixture] | ||
public class UpdateJobTimeoutTest : BaseZeebeTest | ||
{ | ||
[Test] | ||
public async Task ShouldSendRequestAsExpected() | ||
{ | ||
// given | ||
var expectedRequest = new UpdateJobTimeoutRequest() | ||
{ | ||
JobKey = 1024, | ||
Timeout = 2000 | ||
}; | ||
|
||
// when | ||
await ZeebeClient | ||
.NewUpdateJobTimeoutCommand(1024) | ||
.Timeout(new TimeSpan(0, 0, 2)) | ||
.Send(); | ||
|
||
// then | ||
var request = TestService.Requests[typeof(UpdateJobTimeoutRequest)][0]; | ||
Assert.AreEqual(expectedRequest, request); | ||
} | ||
|
||
[Test] | ||
public void ShouldTimeoutRequest() | ||
{ | ||
// given | ||
|
||
// when | ||
var task = ZeebeClient | ||
.NewUpdateJobTimeoutCommand(1024) | ||
.Timeout(new TimeSpan(0, 0, 2)) | ||
.Send(TimeSpan.Zero); | ||
var aggregateException = Assert.Throws<AggregateException>(() => task.Wait()); | ||
var rpcException = (RpcException)aggregateException.InnerExceptions[0]; | ||
|
||
// then | ||
Assert.AreEqual(StatusCode.DeadlineExceeded, rpcException.Status.StatusCode); | ||
} | ||
|
||
[Test] | ||
public void ShouldCancelRequest() | ||
{ | ||
// given | ||
|
||
// when | ||
var task = ZeebeClient | ||
.NewUpdateJobTimeoutCommand(1024) | ||
.Timeout(new TimeSpan(0, 0, 2)) | ||
.Send(new CancellationTokenSource(TimeSpan.Zero).Token); | ||
var aggregateException = Assert.Throws<AggregateException>(() => task.Wait()); | ||
var rpcException = (RpcException)aggregateException.InnerExceptions[0]; | ||
|
||
// then | ||
Assert.AreEqual(StatusCode.Cancelled, rpcException.Status.StatusCode); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using System; | ||
using Zeebe.Client.Api.Responses; | ||
|
||
namespace Zeebe.Client.Api.Commands; | ||
|
||
public interface IUpdateJobTimeoutCommandStep1 | ||
{ | ||
/// <summary> | ||
/// Update the timeout for this job. | ||
/// </summary> | ||
/// | ||
/// <para> | ||
/// If the job's timeout is set to zero, the job will be directly retried. | ||
/// </para> | ||
/// <param name="timeout">The duration of the new timeout as a TimeSpan, starting from the current moment.</param> | ||
/// <returns> | ||
/// The builder for this command. Call <see cref="IFinalCommandStep{T}.Send"/> to complete the command and send it to the broker. | ||
/// </returns> | ||
IUpdateJobTimeoutCommandStep2 Timeout(TimeSpan timeout); | ||
} | ||
|
||
public interface IUpdateJobTimeoutCommandStep2 : IFinalCommandWithRetryStep<IUpdateJobTimeoutResponse> | ||
{ | ||
// the place for new optional parameters | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace Zeebe.Client.Api.Responses | ||
{ | ||
/// <summary> | ||
/// Response for an update job timeout request. | ||
/// </summary> | ||
public interface IUpdateJobTimeoutResponse | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using GatewayProtocol; | ||
using Zeebe.Client.Api.Commands; | ||
using Zeebe.Client.Api.Misc; | ||
using Zeebe.Client.Api.Responses; | ||
using UpdateJobTimeoutResponse = Zeebe.Client.Impl.Responses.UpdateJobTimeoutResponse; | ||
|
||
namespace Zeebe.Client.Impl.Commands; | ||
|
||
public class UpdateJobTimeoutCommand : IUpdateJobTimeoutCommandStep1, IUpdateJobTimeoutCommandStep2 | ||
{ | ||
private readonly UpdateJobTimeoutRequest request; | ||
private readonly Gateway.GatewayClient client; | ||
private readonly IAsyncRetryStrategy asyncRetryStrategy; | ||
|
||
public UpdateJobTimeoutCommand(Gateway.GatewayClient client, IAsyncRetryStrategy asyncRetryStrategy, long jobKey) | ||
{ | ||
request = new UpdateJobTimeoutRequest() | ||
{ | ||
JobKey = jobKey | ||
}; | ||
this.client = client; | ||
this.asyncRetryStrategy = asyncRetryStrategy; | ||
} | ||
|
||
public IUpdateJobTimeoutCommandStep2 Timeout(TimeSpan timeout) | ||
{ | ||
request.Timeout = (long)timeout.TotalMilliseconds; | ||
return this; | ||
} | ||
|
||
public async Task<IUpdateJobTimeoutResponse> Send(TimeSpan? timeout = null, CancellationToken token = default) | ||
{ | ||
var asyncReply = client.UpdateJobTimeoutAsync(request, deadline: timeout?.FromUtcNow(), cancellationToken: token); | ||
await asyncReply.ResponseAsync; | ||
return new UpdateJobTimeoutResponse(); | ||
} | ||
|
||
public async Task<IUpdateJobTimeoutResponse> Send(CancellationToken cancellationToken) | ||
{ | ||
return await Send(token: cancellationToken); | ||
} | ||
|
||
public async Task<IUpdateJobTimeoutResponse> SendWithRetry(TimeSpan? timeout = null, CancellationToken token = default) | ||
{ | ||
return await asyncRetryStrategy.DoWithRetry(() => Send(timeout, token)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using Zeebe.Client.Api.Responses; | ||
|
||
namespace Zeebe.Client.Impl.Responses; | ||
|
||
public class UpdateJobTimeoutResponse : IUpdateJobTimeoutResponse | ||
{ | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍🏼 Great that you added here an test case as well.
As this is only for the SendWithRetry test right now we also need some more tests for the happy path to check the expected requests, and responses. Like we do with the other commands. Take as example this https://github.com/camunda-community-hub/zeebe-client-csharp/blob/main/Client.UnitTests/UpdateRetriesTest.cs
What we also need is to add
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added tests to check expected requests