From f0d83a85f4e57377ba394e545a7e50697764dc73 Mon Sep 17 00:00:00 2001 From: Tom Kerkhove Date: Sun, 7 Apr 2019 11:37:17 +0200 Subject: [PATCH] Support no messages available with TimeSpentInQueue & Storage scraper (#496) Signed-off-by: Tom Kerkhove --- .../AzureStorageQueueClient.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Promitor.Integrations.AzureStorage/AzureStorageQueueClient.cs b/src/Promitor.Integrations.AzureStorage/AzureStorageQueueClient.cs index 0269607dc..ddf728dab 100644 --- a/src/Promitor.Integrations.AzureStorage/AzureStorageQueueClient.cs +++ b/src/Promitor.Integrations.AzureStorage/AzureStorageQueueClient.cs @@ -49,8 +49,13 @@ public async Task GetQueueMessageTimeSpentInQueueAsync(string accountNam { var queue = await GetQueueReference(accountName, queueName, sasToken); - var msg = await queue.PeekMessageAsync(); - var timeSpentInQueue = msg.InsertionTime.HasValue ? DateTime.UtcNow - msg.InsertionTime.Value.UtcDateTime : TimeSpan.Zero; + var message = await queue.PeekMessageAsync(); + + TimeSpan timeSpentInQueue = TimeSpan.Zero; + if (message?.InsertionTime.HasValue == true) + { + timeSpentInQueue = DateTime.UtcNow - message.InsertionTime.Value.UtcDateTime; + } return timeSpentInQueue.TotalSeconds; }