Skip to content

Commit

Permalink
Merge pull request #82 from marcwittke/hotfix/5.1.14
Browse files Browse the repository at this point in the history
InvokeAsync fixed
  • Loading branch information
marcwittke committed Aug 23, 2019
2 parents 8f7e967 + 0171fe5 commit 262ec8e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,29 @@ public void Invoke(Action action, IIdentity identity, TenantId tenantId)
}
}

public async Task InvokeAsync(Action action, IIdentity identity, TenantId tenantId, CancellationToken cancellationToken)
public async Task InvokeAsync(Func<Task> awaitableAsyncAction, IIdentity identity, TenantId tenantId)
{
await Task.Factory.StartNew(() => Invoke(action, identity, tenantId), cancellationToken);
using (BeginScope(new SystemIdentity(), tenantId))
{
using (var unitOfWork = CompositionRoot.GetInstance<IUnitOfWork>())
{
try
{
unitOfWork.Begin();
await awaitableAsyncAction.Invoke();
unitOfWork.Complete();
}
catch (TargetInvocationException ex)
{
ExceptionLogger.LogException(ex.InnerException ?? ex);
}
catch (Exception ex)
{
Logger.Info(ex);
ExceptionLogger.LogException(ex);
}
}
}
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public interface IBackendFxApplication : IDisposable

void Invoke(Action action, IIdentity identity, TenantId tenantId);

Task InvokeAsync(Action action, IIdentity identity, TenantId tenantId, CancellationToken cancellationToken = default);
Task InvokeAsync(Func<Task> awaitableAsyncAction, IIdentity identity, TenantId tenantId);

void Run<TJob>() where TJob : class, IJob;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ protected virtual async Task ProcessAsync(string eventName, EventProcessingConte
foreach (var subscription in subscriptions)
{
await _application.InvokeAsync(
() => subscription.Process(eventName, context),
() => Task.Factory.StartNew(() => subscription.Process(eventName, context)),
new SystemIdentity(),
context.TenantId);
}
Expand All @@ -136,7 +136,7 @@ protected virtual async Task ProcessAsync(string eventName, EventProcessingConte
Logger.Info($"No handler registered. Ignoring {eventName} event");
}
}

protected virtual void Dispose(bool disposing)
{ }

Expand Down

0 comments on commit 262ec8e

Please sign in to comment.