From c755a6058baee7d1391347152de36ed10e313fe4 Mon Sep 17 00:00:00 2001
From: Stephanie Buadu <47737608+acn-sbuad@users.noreply.github.com>
Date: Mon, 4 Dec 2023 14:43:49 +0100
Subject: [PATCH] handle failed_transient error email status #GCPActive (#320)
---
README.md | 2 +-
.../Enums/EmailNotificationResultType.cs | 15 +++++++++-
.../Services/EmailNotificationService.cs | 6 ++++
.../Services/NotificationSummaryService.cs | 4 ++-
.../EmailNotificationServiceTests.cs | 29 +++++++++++++++++++
5 files changed, 53 insertions(+), 3 deletions(-)
diff --git a/README.md b/README.md
index 81f0c0b0..08e0d1f9 100644
--- a/README.md
+++ b/README.md
@@ -63,6 +63,6 @@ In pgAdmin
To run a Kafka broker and Kafdrop (visualization and administration tool) locally you need to have Docker installed on your machine.
In a terminal navigate to the root of this repository
-and run command `docker-compose -f setup-kafka.yml up -d`
+and run command `docker compose -f setup-kafka.yml up -d`
Kafdrop will be available on localhost:9000
diff --git a/src/Altinn.Notifications.Core/Enums/EmailNotificationResultType.cs b/src/Altinn.Notifications.Core/Enums/EmailNotificationResultType.cs
index 65813841..2867520c 100644
--- a/src/Altinn.Notifications.Core/Enums/EmailNotificationResultType.cs
+++ b/src/Altinn.Notifications.Core/Enums/EmailNotificationResultType.cs
@@ -38,5 +38,18 @@ public enum EmailNotificationResultType
///
/// Invalid format for email address
///
- Failed_InvalidEmailFormat
+ Failed_InvalidEmailFormat,
+
+ ///
+ /// Recipient supressed by email service
+ ///
+ Failed_SupressedRecipient,
+
+ ///
+ /// Transient error, retry later
+ ///
+ ///
+ /// Should not be used externally or persisted in db.
+ /// Only used for processing and logic in service layer.
+ Failed_TransientError
}
diff --git a/src/Altinn.Notifications.Core/Services/EmailNotificationService.cs b/src/Altinn.Notifications.Core/Services/EmailNotificationService.cs
index 61453805..9386824c 100644
--- a/src/Altinn.Notifications.Core/Services/EmailNotificationService.cs
+++ b/src/Altinn.Notifications.Core/Services/EmailNotificationService.cs
@@ -72,6 +72,12 @@ public async Task SendNotifications()
///
public async Task UpdateSendStatus(SendOperationResult sendOperationResult)
{
+ // set to new to allow new iteration of regular proceessing if transient error
+ if (sendOperationResult.SendResult == EmailNotificationResultType.Failed_TransientError)
+ {
+ sendOperationResult.SendResult = EmailNotificationResultType.New;
+ }
+
await _repository.UpdateSendStatus(sendOperationResult.NotificationId, (EmailNotificationResultType)sendOperationResult.SendResult!, sendOperationResult.OperationId);
}
diff --git a/src/Altinn.Notifications.Core/Services/NotificationSummaryService.cs b/src/Altinn.Notifications.Core/Services/NotificationSummaryService.cs
index 54a9326a..e618ce0e 100644
--- a/src/Altinn.Notifications.Core/Services/NotificationSummaryService.cs
+++ b/src/Altinn.Notifications.Core/Services/NotificationSummaryService.cs
@@ -20,7 +20,9 @@ public class NotificationSummaryService : INotificationSummaryService
{ EmailNotificationResultType.Delivered, "The email was delivered to the recipient. No errors reported, making it likely it was received by the recipient." },
{ EmailNotificationResultType.Failed, "The email was not sent due to an unspecified failure." },
{ EmailNotificationResultType.Failed_RecipientNotIdentified, "The email was not sent because the recipient's email address was not found." },
- { EmailNotificationResultType.Failed_InvalidEmailFormat, "The email was not sent because the recipient’s email address is in an invalid format." }
+ { EmailNotificationResultType.Failed_InvalidEmailFormat, "The email was not sent because the recipient’s email address is in an invalid format." },
+ { EmailNotificationResultType.Failed_SupressedRecipient, "The email was not sent because the recipient’s email address is suppressed by the third party email service." },
+ { EmailNotificationResultType.Failed_TransientError, "The email was not sent due to a transient error. We will retry sending the email." }
};
private readonly static List _successResults = new()
diff --git a/test/Altinn.Notifications.Tests/Notifications.Core/TestingServices/EmailNotificationServiceTests.cs b/test/Altinn.Notifications.Tests/Notifications.Core/TestingServices/EmailNotificationServiceTests.cs
index 0e254716..505084a1 100644
--- a/test/Altinn.Notifications.Tests/Notifications.Core/TestingServices/EmailNotificationServiceTests.cs
+++ b/test/Altinn.Notifications.Tests/Notifications.Core/TestingServices/EmailNotificationServiceTests.cs
@@ -162,6 +162,35 @@ public async Task UpdateSendStatus_SendResultDefined_Succeded()
repoMock.Verify();
}
+ [Fact]
+ public async Task UpdateSendStatus_TransientErrorResult_ConvertedToNew()
+ {
+ // Arrange
+ Guid notificationid = Guid.NewGuid();
+ string operationId = Guid.NewGuid().ToString();
+
+ SendOperationResult sendOperationResult = new()
+ {
+ NotificationId = notificationid,
+ OperationId = operationId,
+ SendResult = EmailNotificationResultType.Failed_TransientError
+ };
+
+ var repoMock = new Mock();
+ repoMock.Setup(r => r.UpdateSendStatus(
+ It.Is(n => n == notificationid),
+ It.Is(e => e == EmailNotificationResultType.New),
+ It.Is(s => s.Equals(operationId))));
+
+ var service = GetTestService(repo: repoMock.Object);
+
+ // Act
+ await service.UpdateSendStatus(sendOperationResult);
+
+ // Assert
+ repoMock.Verify();
+ }
+
private static EmailNotificationService GetTestService(IEmailNotificationRepository? repo = null, IKafkaProducer? producer = null, Guid? guidOutput = null, DateTime? dateTimeOutput = null)
{
var guidService = new Mock();