mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 13:26:30 +00:00
gps matcher async
put cryptography lib to fixed version fix race condition bug in queue handler add lock to db writing and backup to file db on each write
This commit is contained in:
@@ -32,22 +32,15 @@ public class StartMatchingEvent
|
||||
public class GpsMatcherClient : IGpsMatcherClient
|
||||
{
|
||||
private readonly IMediator _mediator;
|
||||
private readonly GpsDeniedClientConfig _gpsDeniedClientConfig;
|
||||
private string _requestAddress;
|
||||
private readonly string _requestAddress;
|
||||
private readonly RequestSocket _requestSocket = new();
|
||||
private string _subscriberAddress;
|
||||
private readonly string _subscriberAddress;
|
||||
private readonly SubscriberSocket _subscriberSocket = new();
|
||||
|
||||
|
||||
public GpsMatcherClient(IMediator mediator, IOptions<GpsDeniedClientConfig> gpsDeniedClientConfig)
|
||||
public GpsMatcherClient(IMediator mediator, IOptions<GpsDeniedClientConfig> gpsConfig)
|
||||
{
|
||||
_mediator = mediator;
|
||||
_gpsDeniedClientConfig = gpsDeniedClientConfig.Value;
|
||||
Start();
|
||||
}
|
||||
|
||||
private void Start(CancellationToken ct = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
using var process = new Process();
|
||||
@@ -71,16 +64,16 @@ public class GpsMatcherClient : IGpsMatcherClient
|
||||
//throw;
|
||||
}
|
||||
|
||||
_requestAddress = $"tcp://{_gpsDeniedClientConfig.ZeroMqHost}:{_gpsDeniedClientConfig.ZeroMqPort}";
|
||||
_requestAddress = $"tcp://{gpsConfig.Value.ZeroMqHost}:{gpsConfig.Value.ZeroMqPort}";
|
||||
_requestSocket.Connect(_requestAddress);
|
||||
|
||||
_subscriberAddress = $"tcp://{_gpsDeniedClientConfig.ZeroMqHost}:{_gpsDeniedClientConfig.ZeroMqSubscriberPort}";
|
||||
_subscriberAddress = $"tcp://{gpsConfig.Value.ZeroMqHost}:{gpsConfig.Value.ZeroMqSubscriberPort}";
|
||||
_subscriberSocket.Connect(_subscriberAddress);
|
||||
_subscriberSocket.Subscribe("");
|
||||
_subscriberSocket.ReceiveReady += async (_, e) => await ProcessClientCommand(e.Socket, ct);
|
||||
_subscriberSocket.ReceiveReady += async (_, e) => await ProcessClientCommand(e.Socket);
|
||||
}
|
||||
|
||||
private async Task ProcessClientCommand(NetMQSocket socket, CancellationToken ct)
|
||||
private async Task ProcessClientCommand(NetMQSocket socket)
|
||||
{
|
||||
while (socket.TryReceiveFrameString(TimeSpan.Zero, out var str))
|
||||
{
|
||||
@@ -90,10 +83,10 @@ public class GpsMatcherClient : IGpsMatcherClient
|
||||
switch (str)
|
||||
{
|
||||
case "FINISHED":
|
||||
await _mediator.Publish(new GPSMatcherFinishedEvent(), ct);
|
||||
await _mediator.Publish(new GPSMatcherFinishedEvent());
|
||||
break;
|
||||
case "OK":
|
||||
await _mediator.Publish(new GPSMatcherJobAcceptedEvent(), ct);
|
||||
await _mediator.Publish(new GPSMatcherJobAcceptedEvent());
|
||||
break;
|
||||
default:
|
||||
var parts = str.Split(',');
|
||||
@@ -107,7 +100,7 @@ public class GpsMatcherClient : IGpsMatcherClient
|
||||
Latitude = double.Parse(parts[2]),
|
||||
Longitude = double.Parse(parts[3]),
|
||||
MatchType = parts[4]
|
||||
}, ct);
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user