diff --git a/src/ReC.Application/RecActions/Commands/InvokeBatchRecActionsCommand.cs b/src/ReC.Application/RecActions/Commands/InvokeBatchRecActionsCommand.cs index 87770f7..4f27e82 100644 --- a/src/ReC.Application/RecActions/Commands/InvokeBatchRecActionsCommand.cs +++ b/src/ReC.Application/RecActions/Commands/InvokeBatchRecActionsCommand.cs @@ -1,6 +1,4 @@ using MediatR; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; using ReC.Application.RecActions.Queries; namespace ReC.Application.RecActions.Commands; @@ -13,40 +11,13 @@ public static class InvokeBatchRecActionsCommandExtensions => sender.Send(new InvokeBatchRecActionsCommand { ProfileId = profileId }, cancel); } -public class InvokeRecActionsCommandHandler(ISender sender, IServiceScopeFactory scopeFactory, IHttpClientFactory clientFactory, ILogger? logger = null) : IRequestHandler +public class InvokeRecActionsCommandHandler(ISender sender) : IRequestHandler { public async Task Handle(InvokeBatchRecActionsCommand request, CancellationToken cancel) { var actions = await sender.Send(request.ToReadQuery(q => q.Invoked = false), cancel); - var http = clientFactory.CreateClient(); - - using var semaphore = new SemaphoreSlim(5); - - var tasks = actions.Select(async action => - { - await semaphore.WaitAsync(cancel); - try - { - using var scope = scopeFactory.CreateScope(); - var sender = scope.ServiceProvider.GetRequiredService(); - await sender.Send(action.ToInvokeCommand(), cancel); - } - catch(Exception ex) - { - logger?.LogError( - ex, - "Error invoking Rec action. ProfileId: {ProfileId}, Id: {Id}", - action.ProfileId, - action.Id - ); - } - finally - { - semaphore.Release(); - } - }); - - await Task.WhenAll(tasks); + foreach (var action in actions) + await sender.Send(action.ToInvokeCommand(), cancel); } } \ No newline at end of file