Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle failed_transient error email status #GCPActive #320

Merged
merged 2 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,18 @@ public enum EmailNotificationResultType
/// <summary>
/// Invalid format for email address
/// </summary>
Failed_InvalidEmailFormat
Failed_InvalidEmailFormat,

/// <summary>
/// Recipient supressed by email service
/// </summary>
Failed_SupressedRecipient,

/// <summary>
/// Transient error, retry later
/// </summary>
/// <remarks>
/// Should not be used externally or persisted in db.
/// Only used for processing and logic in service layer.</remarks>
Failed_TransientError
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ public async Task SendNotifications()
/// <inheritdoc/>
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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<EmailNotificationResultType> _successResults = new()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<IEmailNotificationRepository>();
repoMock.Setup(r => r.UpdateSendStatus(
It.Is<Guid>(n => n == notificationid),
It.Is<EmailNotificationResultType>(e => e == EmailNotificationResultType.New),
It.Is<string>(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<IGuidService>();
Expand Down
Loading