refactor(email): replace Task.WhenAll with foreach in SendEmailBehavior

Changed the SendFinalEmailToReceiversAsync method to use a sequential `foreach` loop
instead of `Task.WhenAll` for sending history commands. Added a null check for
receiver emails to prevent potential exceptions.
This commit is contained in:
tekh 2025-11-12 16:14:32 +01:00
parent fac5419589
commit 35dd2e8e07
4 changed files with 19 additions and 8 deletions

View File

@ -95,12 +95,18 @@ public class SendEmailBehavior : IPipelineBehavior<BurnPdfCommand, byte[]>
}
// TODO update CreateHistoryCommand to be able to create all records together
await Task.WhenAll(request.Envelope!.EnvelopeReceivers!.Select(receiver => _sender.Send(new CreateHistoryCommand()
foreach (var receiver in request.Envelope.EnvelopeReceivers!)
{
EnvelopeId = request.Envelope!.Id,
if (receiver.Receiver?.EmailAddress != null)
{
await _sender.Send(new CreateHistoryCommand()
{
EnvelopeId = request.Envelope.Id,
Status = EnvelopeStatus.MessageCompletionSent,
UserReference = receiver.Receiver!.EmailAddress,
}, cancel)));
UserReference = receiver.Receiver.EmailAddress,
}, cancel);
}
}
}
private static bool SendFinalEmailWithAttachment(int type) => type == (int)FinalEmailType.YesWithAttachment;

View File

@ -110,6 +110,8 @@ public class BurnPdfCommandHandler : IRequestHandler<BurnPdfCommand, byte[]>
request.Envelope = await envQuery
.Include(env => env.Documents!).ThenInclude(doc => doc.Elements!).ThenInclude(element => element.Annotations)
.Include(env => env.User)
.Include(env => env.EnvelopeReceivers!).ThenInclude(envRcv => envRcv.Receiver)
.FirstOrDefaultAsync(cancel)
?? throw new BadRequestException($"Envelope could not be found. Request details:\n" +
request.ToJson(Format.Json.ForDiagnostics));

View File

@ -1,7 +1,7 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Default": "Error",
"Microsoft.Hosting.Lifetime": "Information"
}
},

View File

@ -1,8 +1,11 @@
{
"FinishEnvelopeJob": {
"CronExpression": "* * * * * ?"
"CronExpression": "0 0/1 * 1/1 * ? *"
},
"EnvelopeTaskApiJob": {
"CronExpression": "* * * * * ?"
"CronExpression": "0 0/1 * 1/1 * ? *"
}
"Expressions": {
"PerSec": "* * * * * ?"
}
}