fix: seal and adjust async usage

This commit is contained in:
Timothy Schenk 2024-03-02 13:15:13 +01:00
parent 7df83c9877
commit 2ec47ae884
Signed by: rainote
SSH key fingerprint: SHA256:pnkNSDwpAnaip00xaZlVFHKKsS7T8UtOomMzvs0yITE

View file

@ -10,7 +10,7 @@ using Wonderking.Packets;
namespace Continuity.AuthServer.Consumers; namespace Continuity.AuthServer.Consumers;
[UsedImplicitly] [UsedImplicitly]
public class PacketConsumer : IConsumer<RawPacket>, IDisposable public sealed class PacketConsumer : IConsumer<RawPacket>, IDisposable
{ {
private readonly ActivitySource _activitySource; private readonly ActivitySource _activitySource;
private readonly PacketDistributorService<OperationCode, AuthSession> _distributorService; private readonly PacketDistributorService<OperationCode, AuthSession> _distributorService;
@ -21,20 +21,19 @@ public class PacketConsumer : IConsumer<RawPacket>, IDisposable
_activitySource = new ActivitySource(nameof(PacketConsumer)); _activitySource = new ActivitySource(nameof(PacketConsumer));
} }
public Task Consume(ConsumeContext<RawPacket> context) public async Task Consume(ConsumeContext<RawPacket> context)
{ {
using var activity = _activitySource?.StartActivity("PacketConsumption"); using var activity = _activitySource?.StartActivity("PacketConsumption");
activity?.SetTag("PacketId", context.Message.OperationCode.ToString()); activity?.SetTag("PacketId", context.Message.OperationCode.ToString());
activity?.SetTag("SessionId", context.Message.Session.Id.ToString()); activity?.SetTag("SessionId", context.Message.Session.Id.ToString());
activity?.SetTag("PacketSize", context.Message.MessageBody.Length); activity?.SetTag("PacketSize", context.Message.MessageBody.Length);
return _distributorService.AddPacketAsync(context.Message.MessageBody, context.Message.OperationCode, await _distributorService.AddPacketAsync(context.Message.MessageBody, context.Message.OperationCode,
context.Message.Session); context.Message.Session);
} }
public void Dispose() public void Dispose()
{ {
_activitySource.Dispose(); _activitySource.Dispose();
GC.SuppressFinalize(this);
} }
} }