Skip to content

Commit

Permalink
Requeue item on exception, don't swallow it (#1453)
Browse files Browse the repository at this point in the history
  • Loading branch information
cscharf committed Jul 10, 2021
1 parent 9f10b16 commit 151934d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 28 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
@@ -1,7 +1,7 @@
<Project>

<PropertyGroup>
<Version>1.41.5</Version>
<Version>1.41.6</Version>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>Bit.$(MSBuildProjectName)</RootNamespace>
</PropertyGroup>
Expand Down
42 changes: 15 additions & 27 deletions src/EventsProcessor/AzureQueueHostedService.cs
Expand Up @@ -3,16 +3,15 @@
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Azure.Storage.Queues;
using Bit.Core;
using Bit.Core.Models.Data;
using Bit.Core.Services;
using Bit.Core.Utilities;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Azure.Storage.Queues;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Bit.Core.Utilities;

namespace Bit.EventsProcessor
{
Expand Down Expand Up @@ -104,35 +103,24 @@ public async Task ProcessQueueMessageAsync(string message, CancellationToken can
return;
}

try
{
_logger.LogInformation("Processing message.");
var events = new List<IEvent>();

var token = JToken.Parse(message);
if (token is JArray)
{
var indexedEntities = token.ToObject<List<EventMessage>>()
.SelectMany(e => EventTableEntity.IndexEvent(e));
events.AddRange(indexedEntities);
}
else if (token is JObject)
{
var eventMessage = token.ToObject<EventMessage>();
events.AddRange(EventTableEntity.IndexEvent(eventMessage));
}
_logger.LogInformation("Processing message.");
var events = new List<IEvent>();

await _eventWriteService.CreateManyAsync(events);
_logger.LogInformation("Processed message.");
}
catch (JsonReaderException)
var token = JToken.Parse(message);
if (token is JArray)
{
_logger.LogError("JsonReaderException: Unable to parse message.");
var indexedEntities = token.ToObject<List<EventMessage>>()
.SelectMany(e => EventTableEntity.IndexEvent(e));
events.AddRange(indexedEntities);
}
catch (JsonSerializationException)
else if (token is JObject)
{
_logger.LogError("JsonSerializationException: Unable to serialize token.");
var eventMessage = token.ToObject<EventMessage>();
events.AddRange(EventTableEntity.IndexEvent(eventMessage));
}

await _eventWriteService.CreateManyAsync(events);
_logger.LogInformation("Processed message.");
}
}
}

0 comments on commit 151934d

Please sign in to comment.