Add CancellationToken support to RecAction methods

Updated the `Invoke` method in `RecActionController` to accept a `CancellationToken` parameter, enabling cancellation handling during execution. Modified the `InvokeBatchRecAction` extension method in `InvokeBatchRecActionsCommandExtensions` to propagate the `CancellationToken` to the `sender.Send` method, ensuring cancellation support for batch action commands.
This commit is contained in:
tekh 2025-12-03 11:31:38 +01:00
parent 6041d57948
commit c34a87771d
2 changed files with 4 additions and 4 deletions

View File

@ -19,9 +19,9 @@ public class RecActionController(IMediator mediator) : ControllerBase
}, cancel));
[HttpPost("{profileId}")]
public async Task<IActionResult> Invoke([FromRoute] int profileId)
public async Task<IActionResult> Invoke([FromRoute] int profileId, CancellationToken cancel)
{
await mediator.InvokeBatchRecAction(profileId);
await mediator.InvokeBatchRecAction(profileId, cancel);
return Accepted();
}

View File

@ -8,8 +8,8 @@ public record InvokeBatchRecActionsCommand : ReadRecActionQueryBase, IRequest;
public static class InvokeBatchRecActionsCommandExtensions
{
public static Task InvokeBatchRecAction(this ISender sender, int profileId)
=> sender.Send(new InvokeBatchRecActionsCommand { ProfileId = profileId });
public static Task InvokeBatchRecAction(this ISender sender, int profileId, CancellationToken cancel = default)
=> sender.Send(new InvokeBatchRecActionsCommand { ProfileId = profileId }, cancel);
}
public class InvokeRecActionsCommandHandler(ISender sender, IHttpClientFactory clientFactory, ILogger<InvokeRecActionsCommandHandler>? logger = null) : IRequestHandler<InvokeBatchRecActionsCommand>