Skip to content
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Text.Json;
using System.Text.Json.Serialization;
using Amazon.SimpleNotificationService;
using Amazon.SimpleNotificationService.Model;
using Microsoft.Extensions.Options;
Expand All @@ -12,6 +13,13 @@ internal sealed class SnsJobNotifier(
IOptions<TextServicesOptions> options,
ILogger<SnsJobNotifier> logger) : IJobNotifier
{
private static readonly JsonSerializerOptions SerializerOptions = new()
{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
Converters = { new JsonStringEnumConverter() },
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
};

public async Task Notify(JobCompletionNotification notification, CancellationToken ct = default)
{
var topicArn = options.Value.Notifications.TopicArn;
Expand All @@ -25,7 +33,7 @@ public async Task Notify(JobCompletionNotification notification, CancellationTok
await sns.PublishAsync(new PublishRequest
{
TopicArn = topicArn,
Message = JsonSerializer.Serialize(notification),
Message = JsonSerializer.Serialize(notification, SerializerOptions),
MessageAttributes = new Dictionary<string, MessageAttributeValue>
{
["MessageType"] = new()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<PackageReference Include="Hangfire.AspNetCore" Version="1.8.23" />
<PackageReference Include="Hangfire.PostgreSql" Version="1.21.1" />
<PackageReference Include="iiif-net" Version="0.3.13" />
<PackageReference Include="MediatR" Version="13.1.0" />
<PackageReference Include="MediatR" Version="12.5.0" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="10.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="10.0.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<PackageReference Include="AsyncKeyedLock" Version="8.0.2" />
<PackageReference Include="AWSSDK.Extensions.NETCore.Setup" Version="4.0.0.0" />
<PackageReference Include="AWSSDK.SecurityToken" Version="4.0.6.8" />
<PackageReference Include="MediatR" Version="13.1.0" />
<PackageReference Include="MediatR" Version="12.5.0" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="10.0.1" />
<PackageReference Include="Serilog.AspNetCore" Version="10.0.0" />
<PackageReference Include="Serilog.Enrichers.ClientInfo" Version="2.9.0" />
Expand Down
20 changes: 20 additions & 0 deletions src/TextServices.Tests/BuilderApi/SnsJobNotifierTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,26 @@ public async Task Notify_SetsMessageTypeAttribute(JobStatus status, string expec
.MustHaveHappenedOnceExactly();
}

[Fact]
public async Task Notify_SerialisesMessageWithCamelCaseStringEnumAndOmitsNullErrors()
{
var sns = A.Fake<IAmazonSimpleNotificationService>();
PublishRequest? captured = null;
A.CallTo(() => sns.PublishAsync(A<PublishRequest>._, A<CancellationToken>._))
.Invokes((PublishRequest r, CancellationToken _) => captured = r)
.Returns(new PublishResponse());

var sut = MakeNotifier(sns, "arn:aws:sns:eu-west-1:123:test-topic");

await sut.Notify(MakeNotification("books/b123", JobStatus.Waiting));

captured.ShouldNotBeNull();
var message = captured.Message;
message.ShouldContain("\"jobId\":\"books/b123\"");
message.ShouldContain("\"status\":\"Waiting\"");
message.ShouldNotContain("errors");
}

// -------------------------------------------------------------------------
// Error handling
// -------------------------------------------------------------------------
Expand Down
Loading