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) } }