Skip to content

Commit

Permalink
Merge pull request #731 from xlegalles/CleanUpCode3
Browse files Browse the repository at this point in the history
style: use file-scope namespace and primary constructor
  • Loading branch information
Zelldon authored Oct 25, 2024
2 parents f46c8de + 011abf4 commit de44584
Show file tree
Hide file tree
Showing 9 changed files with 1,059 additions and 1,098 deletions.
557 changes: 278 additions & 279 deletions Client/IZeebeClient.cs

Large diffs are not rendered by default.

12 changes: 3 additions & 9 deletions Client/Impl/Misc/AccessToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,10 @@ namespace Zeebe.Client.Impl.Misc;
/// <summary>
/// AccessToken, which consist of an token and a dueDate (expiryDate).
/// </summary>
public class AccessToken
public class AccessToken(string token, long dueDate)
{
public string Token { get; set; }
public long DueDate { get; set; }

public AccessToken(string token, long dueDate)
{
Token = token;
DueDate = dueDate;
}
public string Token { get; set; } = token;
public long DueDate { get; set; } = dueDate;

public override string ToString()
{
Expand Down
2 changes: 0 additions & 2 deletions Client/Impl/Misc/PersistedAccessTokenCache.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using Zeebe.Client.Api.Builder;

namespace Zeebe.Client.Impl.Misc;

Expand Down
46 changes: 19 additions & 27 deletions Client/Impl/Misc/TransientGrpcErrorRetryStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,32 @@
using Grpc.Core;
using Zeebe.Client.Api.Misc;

namespace Zeebe.Client.Impl.Misc
{
public class TransientGrpcErrorRetryStrategy : IAsyncRetryStrategy
{
private static readonly StatusCode[] RetrieableCodes = { StatusCode.Unavailable, StatusCode.ResourceExhausted };

private readonly Func<int, TimeSpan> waitTimeProvider;
namespace Zeebe.Client.Impl.Misc;

public TransientGrpcErrorRetryStrategy(Func<int, TimeSpan> waitTimeProvider)
{
this.waitTimeProvider = waitTimeProvider;
}
public class TransientGrpcErrorRetryStrategy(Func<int, TimeSpan> waitTimeProvider) : IAsyncRetryStrategy
{
private static readonly StatusCode[] RetrieableCodes = [StatusCode.Unavailable, StatusCode.ResourceExhausted];

public async Task<TResult> DoWithRetry<TResult>(Func<Task<TResult>> action)
public async Task<TResult> DoWithRetry<TResult>(Func<Task<TResult>> action)
{
var retries = 0;
while (true)
{
var retries = 0;
while (true)
try
{
var result = await action.Invoke();
return result;
}
catch (RpcException exception)
{
try
if (RetrieableCodes.Contains(exception.StatusCode))
{
var result = await action.Invoke();
return result;
var waitTime = waitTimeProvider.Invoke(++retries);
await Task.Delay(waitTime);
}
catch (RpcException exception)
else
{
if (RetrieableCodes.Contains(exception.StatusCode))
{
var waitTime = waitTimeProvider.Invoke(++retries);
await Task.Delay(waitTime);
}
else
{
throw;
}
throw;
}
}
}
Expand Down
89 changes: 44 additions & 45 deletions Client/Impl/Worker/JobClientWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,52 +2,51 @@
using Zeebe.Client.Api.Responses;
using Zeebe.Client.Api.Worker;

namespace Zeebe.Client.Impl.Worker
namespace Zeebe.Client.Impl.Worker;

internal class JobClientWrapper : IJobClient
{
internal class JobClientWrapper : IJobClient
public static JobClientWrapper Wrap(IJobClient client)
{
return new JobClientWrapper(client);
}

public bool ClientWasUsed { get; private set; }

private IJobClient Client { get; }

private JobClientWrapper(IJobClient client)
{
Client = client;
ClientWasUsed = false;
}

public ICompleteJobCommandStep1 NewCompleteJobCommand(long jobKey)
{
ClientWasUsed = true;
return Client.NewCompleteJobCommand(jobKey);
}

public IFailJobCommandStep1 NewFailCommand(long jobKey)
{
ClientWasUsed = true;
return Client.NewFailCommand(jobKey);
}

public IThrowErrorCommandStep1 NewThrowErrorCommand(long jobKey)
{
ClientWasUsed = true;
return Client.NewThrowErrorCommand(jobKey);
}

public void Reset()
{
ClientWasUsed = false;
}

public ICompleteJobCommandStep1 NewCompleteJobCommand(IJob activatedJob)
{
public static JobClientWrapper Wrap(IJobClient client)
{
return new JobClientWrapper(client);
}

public bool ClientWasUsed { get; private set; }

private IJobClient Client { get; }

private JobClientWrapper(IJobClient client)
{
Client = client;
ClientWasUsed = false;
}

public ICompleteJobCommandStep1 NewCompleteJobCommand(long jobKey)
{
ClientWasUsed = true;
return Client.NewCompleteJobCommand(jobKey);
}

public IFailJobCommandStep1 NewFailCommand(long jobKey)
{
ClientWasUsed = true;
return Client.NewFailCommand(jobKey);
}

public IThrowErrorCommandStep1 NewThrowErrorCommand(long jobKey)
{
ClientWasUsed = true;
return Client.NewThrowErrorCommand(jobKey);
}

public void Reset()
{
ClientWasUsed = false;
}

public ICompleteJobCommandStep1 NewCompleteJobCommand(IJob activatedJob)
{
ClientWasUsed = true;
return Client.NewCompleteJobCommand(activatedJob);
}
ClientWasUsed = true;
return Client.NewCompleteJobCommand(activatedJob);
}
}
Loading

0 comments on commit de44584

Please sign in to comment.