Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,3 @@ csharp_style_expression_bodied_local_functions = false:silent

[src/Mindee/Product/**/*.cs]
generated_code = true

51 changes: 51 additions & 0 deletions src/Mindee/ClientOptions/BaseClient.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;

namespace Mindee.ClientOptions
{
/// <summary>
/// Base class for all clients.
/// </summary>
public abstract class BaseClient
{
/// <summary>
/// The logger instance.
/// </summary>
protected readonly ILogger Logger;
/// <summary>
/// The factory used to create the <see cref="Logger"/>.
/// </summary>
protected readonly ILoggerFactory LoggerFactory;

/// <summary>
/// Default constructor.
/// </summary>
/// <param name="loggerFactory">Factory for the logger.</param>
protected BaseClient(ILoggerFactory loggerFactory = null)
{
LoggerFactory = loggerFactory ?? NullLoggerFactory.Instance;
Logger = LoggerFactory.CreateLogger(GetType());
}

/// <summary>
/// Wait and retry logic for polling operations.
/// </summary>
protected async Task ThrottlePollingAttemptAsync(
int tryCounter,
int maxRetries,
BasePollingOptions pollingOptions,
CancellationToken cancellationToken)
{
if (tryCounter >= maxRetries)
{
Logger?.LogDebug("Not waiting, max retries reached.");
return;
}

Logger?.LogDebug($"Waiting {pollingOptions.IntervalMilliSec} before next attempt...");
await Task.Delay(pollingOptions.IntervalMilliSec, cancellationToken);
}
}
}
15 changes: 0 additions & 15 deletions src/Mindee/ClientOptions/BasePollingOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,5 @@ protected void ValidateSettings()
throw new MindeeException($"Cannot set async retry to less than {MinRetries} attempts.");
}
}
Comment thread
ianardee marked this conversation as resolved.

/// <summary>
/// Compute delay in milliseconds before the given polling attempt.
/// </summary>
/// <param name="attemptNumber">1-based polling attempt number.</param>
/// <returns>Delay in milliseconds.</returns>
public int GetRetryDelayMilliSec(int attemptNumber)
{
if (attemptNumber <= 1)
{
return IntervalMilliSec;
}

return (int)Math.Floor(IntervalSec * 1000);
}
}
}
2 changes: 1 addition & 1 deletion src/Mindee/Exceptions/MindeeInputException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Mindee.Exceptions
{
/// <summary>
/// Represent a 400 error, bad requests or malformed, from Mindee API.
/// Represent an invalid or malformed input.
/// </summary>
public class MindeeInputException : MindeeException
{
Expand Down
3 changes: 2 additions & 1 deletion src/Mindee/MindeeLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
namespace Mindee
{
/// <summary>
/// Global Mindee logger.
/// Legacy Static Mindee logger, only used in V1.
/// TODO: refactor to delete this class.
/// </summary>
public static class MindeeLogger
{
Expand Down
Loading
Loading