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
7 changes: 7 additions & 0 deletions src/infra/docs-lambda-index-publisher/LinkIndexProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class LinkIndexProvider(IAmazonS3 s3Client, ILambdaLogger logger, string
{
private string? _etag;
private LinkReferenceRegistry? _linkIndex;
private bool _modified;

private async Task<LinkReferenceRegistry> GetLinkIndex()
{
Expand Down Expand Up @@ -56,12 +57,18 @@ public async Task UpdateLinkIndexEntry(LinkRegistryEntry linkRegistryEntry)
{
{ linkRegistryEntry.Branch, linkRegistryEntry }
});
_modified = true;
logger.LogInformation("Added new entry for {repository}@{branch}", linkRegistryEntry.Repository, linkRegistryEntry.Branch);
}
}

public async Task Save()
{
if (!_modified)
{
logger.LogInformation("Skipping Save() because the link index was not modified");
return;
}
if (_etag == null || _linkIndex == null)
throw new InvalidOperationException("You must call UpdateLinkIndexEntry() before Save()");
var json = LinkReferenceRegistry.Serialize(_linkIndex);
Expand Down
8 changes: 7 additions & 1 deletion src/infra/docs-lambda-index-publisher/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
// See the LICENSE file in the project root for more information

using System.Collections.Concurrent;
using System.Text.Json;
using Amazon.Lambda.Core;
using Amazon.Lambda.RuntimeSupport;
using Amazon.Lambda.Serialization.SystemTextJson;
using Amazon.Lambda.SQSEvents;
using Amazon.S3;
using Amazon.S3.Util;
using Elastic.Documentation;
using Elastic.Documentation.Lambda.LinkIndexUploader;
using Elastic.Documentation.Links;

Expand All @@ -30,6 +30,8 @@ static async Task<SQSBatchResponse> Handler(SQSEvent ev, ILambdaContext context)
var batchItemFailures = new List<SQSBatchResponse.BatchItemFailure>();
foreach (var message in ev.Records)
{
context.Logger.LogInformation("Processing message {MessageId}", message.MessageId);
context.Logger.LogInformation("Message body: {MessageBody}", message.Body);
try
{
var s3RecordLinkReferenceTuples = await GetS3RecordLinkReferenceTuples(s3Client, message, context);
Expand All @@ -55,6 +57,8 @@ static async Task<SQSBatchResponse> Handler(SQSEvent ev, ILambdaContext context)
var response = new SQSBatchResponse(batchItemFailures);
if (batchItemFailures.Count > 0)
context.Logger.LogInformation("Failed to process {batchItemFailuresCount} of {allMessagesCount} messages. Returning them to the queue.", batchItemFailures.Count, ev.Records.Count);
var jsonStr = JsonSerializer.Serialize(response, SerializerContext.Default.SQSBatchResponse);
context.Logger.LogInformation(jsonStr);
return response;
}
catch (Exception ex)
Expand All @@ -67,6 +71,8 @@ static async Task<SQSBatchResponse> Handler(SQSEvent ev, ILambdaContext context)
{
ItemIdentifier = r.MessageId
}).ToList());
var jsonStr = JsonSerializer.Serialize(response, SerializerContext.Default.SQSBatchResponse);
context.Logger.LogInformation(jsonStr);
return response;
}
}
Expand Down
Loading