Skip to content

Commit

Permalink
feat: added implementation for the UpdateJobTimeoutCommand
Browse files Browse the repository at this point in the history
  • Loading branch information
LennartKleymann committed May 22, 2024
1 parent 146a154 commit 29d0799
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 0 deletions.
25 changes: 25 additions & 0 deletions Client/Api/Commands/IUpdateJobTimeoutCommandSteps.cs
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 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
}
9 changes: 9 additions & 0 deletions Client/Api/Responses/IUpdateJobTimeoutResponse.cs
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
{
}
}
25 changes: 25 additions & 0 deletions Client/IZeebeClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,31 @@ public interface IZeebeClient : IJobClient, IDisposable
/// </returns>
IUpdateRetriesCommandStep1 NewUpdateRetriesCommand(long jobKey);

/// <summary>
/// Command to update the timeout of a job.
/// </summary>
/// <example>
/// <code>
/// long jobKey = ..;
///
/// zeebeClient
/// .NewUpdateJobTimeoutCommand(jobKey)
/// .Timeout(new TimeSpan(0, 0, 0, 10))
/// .Send();
/// </code>
/// </example>
///
/// <para>
/// If the job's timeout is zero, the job will be retried.
/// </para>
/// <param name="jobKey">
/// the key of the job to update
/// </param>
/// <returns>
/// a builder for the command
/// </returns>
IUpdateJobTimeoutCommandStep1 NewUpdateJobTimeoutCommand(long jobKey);

/// <summary>
/// Command to deploy new resources, i.e. BPMN process models and DMN decision models.
/// </summary>
Expand Down
50 changes: 50 additions & 0 deletions Client/Impl/Commands/UpdateJobTimeoutCommand.cs
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 = Convert.ToInt32(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));
}
}
8 changes: 8 additions & 0 deletions Client/Impl/Responses/UpdateJobTimeoutResponse.cs
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
{

}
5 changes: 5 additions & 0 deletions Client/ZeebeClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,11 @@ public IUpdateRetriesCommandStep1 NewUpdateRetriesCommand(long jobKey)
return new UpdateRetriesCommand(gatewayClient, asyncRetryStrategy, jobKey);
}

public IUpdateJobTimeoutCommandStep1 NewUpdateJobTimeoutCommand(long jobKey)
{
return new UpdateJobTimeoutCommand(gatewayClient, asyncRetryStrategy, jobKey);
}

public IThrowErrorCommandStep1 NewThrowErrorCommand(long jobKey)
{
return new ThrowErrorCommand(gatewayClient, asyncRetryStrategy, jobKey);
Expand Down

0 comments on commit 29d0799

Please sign in to comment.