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:
parent
1c38fcda85
commit
4e65275a2f
@ -60,19 +60,39 @@ namespace Bit.Notifications
|
|||||||
|
|
||||||
while(!cancellationToken.IsCancellationRequested)
|
while(!cancellationToken.IsCancellationRequested)
|
||||||
{
|
{
|
||||||
var messages = await _queue.GetMessagesAsync(32, TimeSpan.FromMinutes(1),
|
try
|
||||||
null, null, cancellationToken);
|
|
||||||
if(messages.Any())
|
|
||||||
{
|
{
|
||||||
foreach(var message in messages)
|
var messages = await _queue.GetMessagesAsync(32, TimeSpan.FromMinutes(1),
|
||||||
|
null, null, cancellationToken);
|
||||||
|
if(messages.Any())
|
||||||
{
|
{
|
||||||
await HubHelpers.SendNotificationToHubAsync(message.AsString, _hubContext, cancellationToken);
|
foreach(var message in messages)
|
||||||
await _queue.DeleteMessageAsync(message);
|
{
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
catch(Exception e)
|
||||||
{
|
{
|
||||||
await Task.Delay(TimeSpan.FromSeconds(5), cancellationToken);
|
_logger.LogError("Error processing messages.", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user