From c4082f7d0b28ab620437cfdfc5802e3de3a0da04 Mon Sep 17 00:00:00 2001 From: David Wiseman <33157668+DavidWiseman@users.noreply.github.com> Date: Tue, 25 Jun 2024 09:03:53 +0100 Subject: [PATCH] SQS Message handling update - delay Update message processing delay. Reduce time between loops and add additional delay for error conditions. --- DBADash/Messaging/SQSMessageProcessing.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/DBADash/Messaging/SQSMessageProcessing.cs b/DBADash/Messaging/SQSMessageProcessing.cs index c13b6cbc..b335f28f 100644 --- a/DBADash/Messaging/SQSMessageProcessing.cs +++ b/DBADash/Messaging/SQSMessageProcessing.cs @@ -27,7 +27,8 @@ public class SQSMessageProcessing private const int clearMessageVisibilityTimeout = 0; //ms private const int messageVisibilityTimeout = 10000; //ms private const int delayAfterReceivingMessageForDifferentAgent = 1000; // ms - private const int delayBetweenMessages = 1000; // ms + private const int delayBetweenMessages = 100; // ms + private const int errorDelay= 1000; // ms private AsyncRetryPolicy _retryPolicy; private readonly ConcurrentDictionary _semaphores = new(); private const int MaxDegreeOfParallelism = 2; @@ -66,7 +67,6 @@ public async Task ProcessSQSQueue(string DBADashAgentIdentifier) MessageAttributeNames = new List { "All" }, MessageSystemAttributeNames = new List { MessageSystemAttributeName.SentTimestamp } }; - while (true) { try @@ -121,6 +121,7 @@ await AWSTools.DeleteMessageAsync(_sqsClient, Config.ServiceSQSQueueUrl, { // Handle any exceptions that occurred during processing Log.Error(ex, $"Error processing message: {message.Body}"); + await Task.Delay(errorDelay); // Extra delay if error occurs to avoid burning CPU cycles } } } @@ -128,9 +129,10 @@ await AWSTools.DeleteMessageAsync(_sqsClient, Config.ServiceSQSQueueUrl, catch (Exception ex) { Log.Error(ex, "Error receiving messages from SQS Queue"); + await Task.Delay(errorDelay); // Extra delay if error occurs to avoid burning CPU cycles } - await Task.Delay(delayBetweenMessages); + await Task.Delay(delayBetweenMessages); // Wait a small amount of time before checking for more messages to avoid burning CPU cycles (shouldn't be required) } }