Introduce ErrorAction property to RecActionDto for per-action error handling. Update InvokeRecActionsCommandHandler to check invocation results and use ErrorAction to determine whether to continue or stop on failure, enabling configurable batch processing behavior. Add ErrorAction to RecActionDto and batch error handling Introduce ErrorAction property to RecActionDto for per-action error handling. Update InvokeRecActionsCommandHandler to check invocation results and use ErrorAction to determine whether to continue or stop processing on failure. This enables configurable error handling in batch action execution.
33 lines
1.1 KiB
C#
33 lines
1.1 KiB
C#
using MediatR;
|
|
using ReC.Application.RecActions.Queries;
|
|
|
|
namespace ReC.Application.RecActions.Commands;
|
|
|
|
public record InvokeBatchRecActionsCommand : ReadRecActionQueryBase, IRequest;
|
|
|
|
public static class InvokeBatchRecActionsCommandExtensions
|
|
{
|
|
public static Task InvokeBatchRecAction(this ISender sender, long profileId, CancellationToken cancel = default)
|
|
=> sender.Send(new InvokeBatchRecActionsCommand { ProfileId = profileId }, cancel);
|
|
}
|
|
|
|
public class InvokeRecActionsCommandHandler(ISender sender) : IRequestHandler<InvokeBatchRecActionsCommand>
|
|
{
|
|
public async Task Handle(InvokeBatchRecActionsCommand request, CancellationToken cancel)
|
|
{
|
|
var actions = await sender.Send(request.ToReadQuery(q => q.Invoked = false), cancel);
|
|
|
|
foreach (var action in actions)
|
|
{
|
|
var ok = await sender.Send(action.ToInvokeCommand(), cancel);
|
|
if (!ok)
|
|
switch (action.ErrorAction?.ToLowerInvariant())
|
|
{
|
|
case "continue":
|
|
break;
|
|
default:
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
} |