1
0
mirror of https://github.com/bitwarden/server.git synced 2025-04-05 21:18:13 -05:00

catch errors when processing notification messages

This commit is contained in:
Kyle Spearrin 2019-05-07 22:06:05 -04:00
parent 1c38fcda85
commit 4e65275a2f

View File

@ -59,6 +59,8 @@ namespace Bit.Notifications
_queue = queueClient.GetQueueReference("notifications");
while(!cancellationToken.IsCancellationRequested)
{
try
{
var messages = await _queue.GetMessagesAsync(32, TimeSpan.FromMinutes(1),
null, null, cancellationToken);
@ -66,15 +68,33 @@ namespace Bit.Notifications
{
foreach(var message in messages)
{
await HubHelpers.SendNotificationToHubAsync(message.AsString, _hubContext, cancellationToken);
try
{
await HubHelpers.SendNotificationToHubAsync(
message.AsString, _hubContext, cancellationToken);
await _queue.DeleteMessageAsync(message);
}
catch(Exception e)
{
_logger.LogError("Error processing dequeued message: " +
$"{message.Id} x{message.DequeueCount}.", e);
if(message.DequeueCount > 2)
{
await _queue.DeleteMessageAsync(message);
}
}
}
}
else
{
await Task.Delay(TimeSpan.FromSeconds(5), cancellationToken);
}
}
catch(Exception e)
{
_logger.LogError("Error processing messages.", e);
}
}
}
}
}