Skip to content

Commit

Permalink
fix: retry workflow works with async/awat
Browse files Browse the repository at this point in the history
  • Loading branch information
ethno2405 committed Aug 29, 2022
1 parent fac974a commit ae58926
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 22 deletions.
5 changes: 1 addition & 4 deletions src/Elders.Cronus/FaultHandling/InMemoryRetryWorkflow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ protected override async Task RunAsync(Execution<TContext> execution)
if (execution is null) throw new ArgumentNullException(nameof(execution));

TContext context = execution.Context;
await retryPolicy.ExecuteAction(() =>
{
return workflow.RunAsync(execution.Context).ConfigureAwait(false);
});
await retryPolicy.ExecuteAction(() => workflow.RunAsync(execution.Context));
}
}
}
17 changes: 4 additions & 13 deletions src/Elders.Cronus/FaultHandling/RetryPolicy.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using Elders.Cronus.FaultHandling.Strategies;
using Microsoft.Extensions.Logging;

Expand Down Expand Up @@ -115,24 +116,13 @@ public RetryPolicy(ITransientErrorDetectionStrategy errorDetectionStrategy, int
/// </summary>
public ITransientErrorDetectionStrategy ErrorDetectionStrategy { get; private set; }

/// <summary>
/// Repetitively executes the specified action while it satisfies the current retry policy.
/// </summary>
/// <param name="action">A delegate representing the executable action which doesn't return any results.</param>
public virtual void ExecuteAction(Action action)
{
//Guard.ArgumentNotNull(action, "action");

this.ExecuteAction(() => { action(); return default(object); });
}

/// <summary>
/// Repetitively executes the specified action while it satisfies the current retry policy.
/// </summary>
/// <typeparam name="TResult">The type of result expected from the executable action.</typeparam>
/// <param name="func">A delegate representing the executable action which returns the result of type R.</param>
/// <returns>The result from the action.</returns>
public virtual TResult ExecuteAction<TResult>(Func<TResult> func)
public virtual async Task<TResult> ExecuteAction<TResult>(Func<Task<TResult>> func)
{
//Guard.ArgumentNotNull(func, "func");

Expand All @@ -148,7 +138,8 @@ public virtual TResult ExecuteAction<TResult>(Func<TResult> func)

try
{
return func();
var result = await func();
return result;
}
catch (RetryLimitExceededException limitExceededEx)
{
Expand Down
5 changes: 0 additions & 5 deletions src/Elders.Cronus/Workflow/Workflow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ protected override async Task<object> AbstractRunAsync(Execution<TContext> execu
return default(object);
}

new public Task RunAsync(TContext context)
{
return base.RunAsync(context);
}

protected abstract Task RunAsync(Execution<TContext> execution);
}

Expand Down

0 comments on commit ae58926

Please sign in to comment.