mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 18:06:39 +00:00
big refactoring. get rid of static properties and coupled architecture. prepare system for integration tests
This commit is contained in:
@@ -20,6 +20,8 @@ public interface IInferenceClient : IDisposable
|
||||
public class InferenceClient : IInferenceClient
|
||||
{
|
||||
private readonly ILogger<InferenceClient> _logger;
|
||||
private readonly IProcessLauncher _processLauncher;
|
||||
private readonly IDetectionClassProvider _classProvider;
|
||||
|
||||
private readonly DealerSocket _dealer = new();
|
||||
private readonly NetMQPoller _poller = new();
|
||||
@@ -30,12 +32,16 @@ public class InferenceClient : IInferenceClient
|
||||
|
||||
public InferenceClient(ILogger<InferenceClient> logger, IOptions<InferenceClientConfig> inferenceConfig,
|
||||
IMediator mediator,
|
||||
IOptions<LoaderClientConfig> loaderConfig)
|
||||
IOptions<LoaderClientConfig> loaderConfig,
|
||||
IProcessLauncher processLauncher,
|
||||
IDetectionClassProvider classProvider)
|
||||
{
|
||||
_logger = logger;
|
||||
_inferenceClientConfig = inferenceConfig.Value;
|
||||
_loaderClientConfig = loaderConfig.Value;
|
||||
_mediator = mediator;
|
||||
_processLauncher = processLauncher;
|
||||
_classProvider = classProvider;
|
||||
Start();
|
||||
}
|
||||
|
||||
@@ -43,14 +49,9 @@ public class InferenceClient : IInferenceClient
|
||||
{
|
||||
try
|
||||
{
|
||||
using var process = new Process();
|
||||
process.StartInfo = new ProcessStartInfo
|
||||
{
|
||||
FileName = Constants.EXTERNAL_INFERENCE_PATH,
|
||||
Arguments = $"-p {_inferenceClientConfig.ZeroMqPort} -lp {_loaderClientConfig.ZeroMqPort} -a {_inferenceClientConfig.ApiUrl}",
|
||||
CreateNoWindow = true
|
||||
};
|
||||
process.Start();
|
||||
_processLauncher.Launch(
|
||||
Constants.EXTERNAL_INFERENCE_PATH,
|
||||
$"-p {_inferenceClientConfig.ZeroMqPort} -lp {_loaderClientConfig.ZeroMqPort} -a {_inferenceClientConfig.ApiUrl}");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
@@ -77,7 +78,9 @@ public class InferenceClient : IInferenceClient
|
||||
{
|
||||
case CommandType.InferenceData:
|
||||
var annotationImage = MessagePackSerializer.Deserialize<AnnotationImage>(remoteCommand.Data, cancellationToken: ct);
|
||||
_logger.LogInformation("Received command: {AnnotationImage}", annotationImage.ToString());
|
||||
var className = _classProvider.GetClassName(annotationImage);
|
||||
_logger.LogInformation("Received command: Annotation {Name} {Time} - {ClassName}",
|
||||
annotationImage.Name, annotationImage.TimeStr, className);
|
||||
await _mediator.Publish(new InferenceDataEvent(annotationImage), ct);
|
||||
break;
|
||||
case CommandType.InferenceStatus:
|
||||
|
||||
@@ -7,6 +7,7 @@ namespace Azaion.Common.Services.Inference;
|
||||
|
||||
public interface IInferenceService
|
||||
{
|
||||
Task StartAsync();
|
||||
Task RunInference(List<string> mediaPaths, CameraConfig cameraConfig, CancellationToken ct = default);
|
||||
CancellationTokenSource InferenceCancelTokenSource { get; set; }
|
||||
CancellationTokenSource CheckAIAvailabilityTokenSource { get; set; }
|
||||
@@ -28,12 +29,17 @@ public class InferenceService : IInferenceService
|
||||
_client = client;
|
||||
_azaionApi = azaionApi;
|
||||
_aiConfigOptions = aiConfigOptions;
|
||||
_ = Task.Run(async () => await CheckAIAvailabilityStatus());
|
||||
}
|
||||
|
||||
public CancellationTokenSource InferenceCancelTokenSource { get; set; } = new();
|
||||
public CancellationTokenSource CheckAIAvailabilityTokenSource { get; set; } = new();
|
||||
|
||||
public async Task StartAsync()
|
||||
{
|
||||
_ = Task.Run(async () => await CheckAIAvailabilityStatus());
|
||||
await Task.CompletedTask;
|
||||
}
|
||||
|
||||
private async Task CheckAIAvailabilityStatus()
|
||||
{
|
||||
CheckAIAvailabilityTokenSource = new CancellationTokenSource();
|
||||
|
||||
Reference in New Issue
Block a user