Cleaned up request acks. Added internal service bus for internal messaging.
This commit is contained in:
38
Hermes/Socket/Requests/RequestAckManager.cs
Normal file
38
Hermes/Socket/Requests/RequestAckManager.cs
Normal 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.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user