Skip to content

Commit

Permalink
SQS Message handling update - delay
Browse files Browse the repository at this point in the history
Update message processing delay.  Reduce time between loops and add additional delay for error conditions.
  • Loading branch information
DavidWiseman committed Jun 25, 2024
1 parent d7b1639 commit c4082f7
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions DBADash/Messaging/SQSMessageProcessing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, SemaphoreSlim> _semaphores = new();
private const int MaxDegreeOfParallelism = 2;
Expand Down Expand Up @@ -66,7 +67,6 @@ public async Task ProcessSQSQueue(string DBADashAgentIdentifier)
MessageAttributeNames = new List<string> { "All" },
MessageSystemAttributeNames = new List<string> { MessageSystemAttributeName.SentTimestamp }
};

while (true)
{
try
Expand Down Expand Up @@ -121,16 +121,18 @@ public async Task ProcessSQSQueue(string DBADashAgentIdentifier)
{
// 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
}
}
}
}
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)
}
}

Expand Down

0 comments on commit c4082f7

Please sign in to comment.