optimize TwilioMessageQueueService.cs

optimize TwilioMessageQueueService.cs
This commit is contained in:
易磊 2024-10-18 13:58:57 +08:00 committed by GitHub
parent b77fb87a5e
commit e9194b8247
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -28,19 +28,22 @@ namespace BotSharp.Plugin.Twilio.Services
await foreach (var message in _queue.Reader.ReadAllAsync(stoppingToken))
{
await _throttler.WaitAsync(stoppingToken);
try
_ = Task.Run(async () =>
{
Console.WriteLine($"Start processing {message}.");
await ProcessUserMessageAsync(message);
}
catch (Exception ex)
{
Console.WriteLine($"Processing {message} failed due to {ex.Message}.");
}
finally
{
_throttler.Release();
}
try
{
Console.WriteLine($"Start processing {message}.");
await ProcessUserMessageAsync(message);
}
catch (Exception ex)
{
Console.WriteLine($"Processing {message} failed due to {ex.Message}.");
}
finally
{
_throttler.Release();
}
});
}
}