From 263dfda9c42a36428ad4aac4f77d0367a20a379c Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Fri, 24 Aug 2018 11:23:39 -0400 Subject: [PATCH] some logging from queue service --- src/Notifications/AzureQueueHostedService.cs | 38 ++++++++++++-------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/src/Notifications/AzureQueueHostedService.cs b/src/Notifications/AzureQueueHostedService.cs index 05baf77cf6..df67d6bd23 100644 --- a/src/Notifications/AzureQueueHostedService.cs +++ b/src/Notifications/AzureQueueHostedService.cs @@ -60,26 +60,34 @@ namespace Bit.Notifications var queueClient = storageAccount.CreateCloudQueueClient(); _queue = queueClient.GetQueueReference("notifications"); - while(!cancellationToken.IsCancellationRequested) + _logger.LogInformation("starting queue read"); + try { - var messages = await _queue.GetMessagesAsync(32, TimeSpan.FromMinutes(1), - null, null, cancellationToken); - if(messages.Any()) + while(!cancellationToken.IsCancellationRequested) { - foreach(var message in messages) + var messages = await _queue.GetMessagesAsync(32, TimeSpan.FromMinutes(1), + null, null, cancellationToken); + if(messages.Any()) { - var notificationJson = message.AsString; - var notification = JsonConvert.DeserializeObject>( - notificationJson); - await HubHelpers.SendNotificationToHubAsync(notification.Type, notificationJson, - _hubContext, cancellationToken); - await _queue.DeleteMessageAsync(message); + foreach(var message in messages) + { + var notificationJson = message.AsString; + var notification = JsonConvert.DeserializeObject>( + notificationJson); + await HubHelpers.SendNotificationToHubAsync(notification.Type, notificationJson, + _hubContext, cancellationToken); + await _queue.DeleteMessageAsync(message); + } + } + else + { + await Task.Delay(TimeSpan.FromSeconds(5), cancellationToken); } } - else - { - await Task.Delay(TimeSpan.FromSeconds(5), cancellationToken); - } + } + catch(Exception e) + { + _logger.LogError(e, "error from queue"); } } }