Removed the check that blocked rec action invocation if results already existed for a batch. Also updated using directives for exception handling and logging.
57 lines
2.1 KiB
C#
57 lines
2.1 KiB
C#
using MediatR;
|
|
using Microsoft.Extensions.Logging;
|
|
using ReC.Application.Common.Exceptions;
|
|
using ReC.Application.RecActions.Queries;
|
|
using ReC.Domain.Constants;
|
|
|
|
namespace ReC.Application.RecActions.Commands;
|
|
|
|
public record InvokeBatchRecActionViewsCommand : IRequest
|
|
{
|
|
public long ProfileId { get; init; }
|
|
public required InvokeReferences References { get; init; }
|
|
}
|
|
|
|
public class InvokeRecActionViewsCommandHandler(ISender sender, ILogger<InvokeRecActionViewsCommandHandler>? logger = null) : IRequestHandler<InvokeBatchRecActionViewsCommand>
|
|
{
|
|
public async Task Handle(InvokeBatchRecActionViewsCommand request, CancellationToken cancel)
|
|
{
|
|
var actions = await sender.Send(new ReadRecActionViewQuery() { ProfileId = request.ProfileId }, cancel);
|
|
|
|
foreach (var action in actions)
|
|
{
|
|
try
|
|
{
|
|
await sender.Send(new InvokeRecActionViewCommand()
|
|
{
|
|
Action = action,
|
|
References = request.References
|
|
}, cancel);
|
|
}
|
|
catch (RecActionException ex)
|
|
{
|
|
switch (action.ErrorAction)
|
|
{
|
|
case ErrorAction.Continue:
|
|
logger?.LogWarning(ex, "Rec action failed but continuing. ActionId: {ActionId}, ProfileId: {ProfileId}", ex.ActionId, ex.ProfileId);
|
|
break;
|
|
default:
|
|
// Rethrow the exception to stop processing further actions
|
|
throw;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
switch (action.ErrorAction)
|
|
{
|
|
case ErrorAction.Continue:
|
|
logger?.LogError(ex, "Unexpected error during rec action. ActionId: {ActionId}, ProfileId: {ProfileId}", action.Id, action.ProfileId);
|
|
break;
|
|
default:
|
|
// Rethrow the exception to stop processing further actions
|
|
throw;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |