Cleaned up request acks. Added internal service bus for internal messaging.
This commit is contained in:
45
Hermes/Socket/Requests/UpdatePolicyAck.cs
Normal file
45
Hermes/Socket/Requests/UpdatePolicyAck.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using System.Text.Json;
|
||||
using HermesSocketServer.Models;
|
||||
using Serilog;
|
||||
using TwitchChatTTS.Chat.Commands.Limits;
|
||||
using TwitchChatTTS.Chat.Groups;
|
||||
|
||||
namespace TwitchChatTTS.Hermes.Socket.Requests
|
||||
{
|
||||
public class UpdatePolicyAck : IRequestAck
|
||||
{
|
||||
public string Name => "update_policy";
|
||||
private readonly IChatterGroupManager _groups;
|
||||
private readonly IUsagePolicy<long> _policies;
|
||||
private readonly JsonSerializerOptions _options;
|
||||
private readonly ILogger _logger;
|
||||
|
||||
public UpdatePolicyAck(IChatterGroupManager groups, IUsagePolicy<long> policies, JsonSerializerOptions options, ILogger logger)
|
||||
{
|
||||
_groups = groups;
|
||||
_policies = policies;
|
||||
_options = options;
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
public void Acknowledge(string requestId, string json, IDictionary<string, object>? requestData)
|
||||
{
|
||||
var policy = JsonSerializer.Deserialize<PolicyMessage>(json, _options);
|
||||
if (policy == null)
|
||||
{
|
||||
_logger.Warning($"Policy data failed: null");
|
||||
return;
|
||||
}
|
||||
var group = _groups.Get(policy.GroupId.ToString());
|
||||
if (group == null)
|
||||
{
|
||||
_logger.Warning($"Policy data failed: group id not found [group id: {policy.GroupId}][policy id: {policy.Id}]");
|
||||
return;
|
||||
}
|
||||
|
||||
_logger.Debug($"Policy data loaded [policy id: {policy.Id}][path: {policy.Path}][group id: {policy.GroupId}][group name: {group.Name}]");
|
||||
_policies.Set(group.Name, policy.Path, policy.Usage, TimeSpan.FromMilliseconds(policy.Span));
|
||||
_logger.Information($"Policy has been updated [policy id: {policy.Id}]");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user