TelemetryWorker: handle case when publisher is null
This commit is contained in:
parent
fab4127ace
commit
fa6ca8d226
1 changed files with 7 additions and 3 deletions
|
@ -14,14 +14,18 @@ namespace NucuCar.Sensors.Telemetry
|
||||||
{
|
{
|
||||||
private readonly int _interval;
|
private readonly int _interval;
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
private readonly SensorTelemetry _sensorTelemetry;
|
private readonly TelemetryPublisher _telemetryPublisher;
|
||||||
|
|
||||||
public TelemetryBackgroundWorker(ILogger<TelemetryBackgroundWorker> logger, IConfiguration configuration,
|
public TelemetryBackgroundWorker(ILogger<TelemetryBackgroundWorker> logger, IConfiguration configuration,
|
||||||
SensorTelemetry sensorTelemetry)
|
SensorTelemetry sensorTelemetry)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_interval = configuration.GetValue<int>("Telemetry:Interval");
|
_interval = configuration.GetValue<int>("Telemetry:Interval");
|
||||||
_sensorTelemetry = sensorTelemetry;
|
_telemetryPublisher = sensorTelemetry.Publisher;
|
||||||
|
if (_telemetryPublisher == null)
|
||||||
|
{
|
||||||
|
logger.LogCritical("Invalid state! TelemetryPublisher is null!");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||||
|
@ -30,7 +34,7 @@ namespace NucuCar.Sensors.Telemetry
|
||||||
while (!stoppingToken.IsCancellationRequested)
|
while (!stoppingToken.IsCancellationRequested)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("Is publishing telemetry data!");
|
_logger.LogInformation("Is publishing telemetry data!");
|
||||||
await _sensorTelemetry.Publisher.PublishAsync(stoppingToken);
|
await _telemetryPublisher.PublishAsync(stoppingToken);
|
||||||
await Task.Delay(_interval, stoppingToken);
|
await Task.Delay(_interval, stoppingToken);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue