Cleaned up request acks. Added internal service bus for internal messaging.

This commit is contained in:
Tom
2024-11-08 15:32:42 +00:00
parent fe2eb86a08
commit 66f2bf7ec6
33 changed files with 1326 additions and 415 deletions

View File

@@ -0,0 +1,38 @@
using Serilog;
namespace TwitchChatTTS.Hermes.Socket.Requests
{
public class RequestAckManager
{
private readonly IDictionary<string, IRequestAck> _acknowledgements;
private readonly ILogger _logger;
public RequestAckManager(IEnumerable<IRequestAck> acks, ILogger logger)
{
_acknowledgements = acks.ToDictionary(a => a.Name, a => a);
_logger = logger;
}
public void Fulfill(string type, string requestId, string data, IDictionary<string, object>? requestData)
{
if (data == null)
return;
if (!_acknowledgements.TryGetValue(type, out var ack))
{
_logger.Warning($"Found unknown request type when acknowledging [type: {type}]");
return;
}
_logger.Debug($"Request acknowledgement found [type: {type}][data: {data}]");
try
{
ack.Acknowledge(requestId, data, requestData);
_logger.Debug($"Request acknowledged without error [type: {type}][data: {data}]");
}
catch (Exception ex)
{
_logger.Error(ex, "Failed to fulfill a request ackowledgement.");
}
}
}
}