Skip to content

Commit 4f8561d

Browse files
committed
ok
1 parent dcd5959 commit 4f8561d

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

src/infra/docs-lambda-index-publisher/Models.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ namespace Elastic.Documentation.Lambda.LinkIndexUploader;
1010

1111
[JsonSerializable(typeof(SQSEvent))]
1212
[JsonSerializable(typeof(S3EventNotification))]
13-
public partial class SQSEventSerializerContext : JsonSerializerContext;
13+
[JsonSerializable(typeof(SQSBatchResponse))]
14+
public partial class LinkIndexUpdaterSerializerContext : JsonSerializerContext;
1415

1516
public class S3EventNotification
1617
{
@@ -30,7 +31,7 @@ public class S3EventRecord
3031
public class S3Event
3132
{
3233
[JsonPropertyName("object")]
33-
public S3Object S3Object { get; set; } = new();
34+
public S3Object Obj { get; set; } = new();
3435

3536
[JsonPropertyName("bucket")]
3637
public S3Bucket Bucket { get; set; } = new();

src/infra/docs-lambda-index-publisher/Program.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
const string bucketName = "elastic-docs-link-index";
1818
const string indexFile = "link-index-test.json";
1919

20-
await LambdaBootstrapBuilder.Create<SQSEvent>(Handler, new SourceGeneratorLambdaJsonSerializer<SQSEventSerializerContext>())
20+
await LambdaBootstrapBuilder.Create<SQSEvent>(Handler, new SourceGeneratorLambdaJsonSerializer<LinkIndexUpdaterSerializerContext>())
2121
.Build()
2222
.RunAsync();
2323

@@ -82,8 +82,8 @@ static async Task<SQSBatchResponse> Handler(SQSEvent ev, ILambdaContext context)
8282
catch (Exception ex)
8383
{
8484
// if we fail to update the object, we need to return all the messages
85-
context.Logger.LogError($"Failed to update {bucketName}/{indexFile}. Returning all messages to the queue.");
86-
context.Logger.LogError(ex.Message);
85+
context.Logger.LogError($"Failed to update {bucketName}/{indexFile}. Returning all {ev.Records.Count} messages to the queue.");
86+
context.Logger.LogError(ex, ex.Message);
8787
return new SQSBatchResponse(ev.Records.Select(r => new SQSBatchResponse.BatchItemFailure
8888
{
8989
ItemIdentifier = r.MessageId
@@ -96,14 +96,14 @@ static async Task<SQSBatchResponse> Handler(SQSEvent ev, ILambdaContext context)
9696
if (string.IsNullOrEmpty(message.Body))
9797
throw new Exception("No Body in SQS Message.");
9898
context.Logger.LogInformation($"Received message {message.Body}");
99-
var s3Event = JsonSerializer.Deserialize<S3EventNotification>(message.Body, SQSEventSerializerContext.Default.S3EventNotification);
99+
var s3Event = JsonSerializer.Deserialize<S3EventNotification>(message.Body, LinkIndexUpdaterSerializerContext.Default.S3EventNotification);
100100
if (s3Event?.Records == null || s3Event.Records.Count == 0)
101101
throw new Exception("Invalid S3 event message format");
102102
var linkReferences = new ConcurrentBag<(S3EventRecord, LinkReference)>();
103103
await Parallel.ForEachAsync(s3Event.Records, async (record, ctx) =>
104104
{
105105
var s3Bucket = record.S3.Bucket;
106-
var s3Object = record.S3.S3Object;
106+
var s3Object = record.S3.Obj;
107107
context.Logger.LogInformation($"Get object {s3Object.Key} from bucket {s3Bucket.Name}");
108108
var getObjectResponse = await s3Client.GetObjectAsync(s3Bucket.Name, s3Object.Key, ctx);
109109
await using var stream = getObjectResponse.ResponseStream;
@@ -118,7 +118,7 @@ await Parallel.ForEachAsync(s3Event.Records, async (record, ctx) =>
118118

119119
static void UpdateLinkIndex(LinkIndex linkIndex, LinkReference linkReference, S3EventRecord s3EventRecord, ILambdaContext context)
120120
{
121-
var s3Object = s3EventRecord.S3.S3Object;
121+
var s3Object = s3EventRecord.S3.Obj;
122122
var keyTokens = s3Object.Key.Split('/');
123123
var repository = keyTokens[1];
124124
var branch = keyTokens[2];

0 commit comments

Comments
 (0)