NUC-3: Fix unhandled TaskCanceledException in SensorWorker.cs and TelemetryWorker.cs
This commit is contained in:
parent
fb689b2440
commit
2658e49687
3 changed files with 12 additions and 2 deletions
|
@ -51,6 +51,10 @@ namespace NucuCar.Telemetry
|
||||||
await Task.Delay(_interval, stoppingToken);
|
await Task.Delay(_interval, stoppingToken);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (TaskCanceledException)
|
||||||
|
{
|
||||||
|
_logger?.LogInformation("The TelemetryWorker task was canceled.");
|
||||||
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
_logger?.LogError($"Unhandled exception in TelemetryWorker. {e.Message}");
|
_logger?.LogError($"Unhandled exception in TelemetryWorker. {e.Message}");
|
||||||
|
|
|
@ -31,9 +31,11 @@ namespace NucuCar.Sensors
|
||||||
services.AddSingleton<ISensor<Bme680Sensor>, Bme680Sensor>();
|
services.AddSingleton<ISensor<Bme680Sensor>, Bme680Sensor>();
|
||||||
services.AddSingleton<ISensor<CpuTempSensor>, CpuTempSensor>();
|
services.AddSingleton<ISensor<CpuTempSensor>, CpuTempSensor>();
|
||||||
services.AddSingleton<ISensor<HeartbeatSensor>, HeartbeatSensor>();
|
services.AddSingleton<ISensor<HeartbeatSensor>, HeartbeatSensor>();
|
||||||
|
|
||||||
// Workers
|
// Workers
|
||||||
|
// Telemetry
|
||||||
services.AddHostedService<TelemetryWorker>();
|
services.AddHostedService<TelemetryWorker>();
|
||||||
|
// Sensors
|
||||||
services.AddHostedService<Bme680Worker>();
|
services.AddHostedService<Bme680Worker>();
|
||||||
services.AddHostedService<CpuTempWorker>();
|
services.AddHostedService<CpuTempWorker>();
|
||||||
services.AddHostedService<HeartbeatWorker>();
|
services.AddHostedService<HeartbeatWorker>();
|
||||||
|
|
|
@ -67,9 +67,13 @@ namespace NucuCar.Sensors
|
||||||
|
|
||||||
TelemetryPublisher?.UnRegisterTelemeter(Sensor);
|
TelemetryPublisher?.UnRegisterTelemeter(Sensor);
|
||||||
}
|
}
|
||||||
|
catch (TaskCanceledException)
|
||||||
|
{
|
||||||
|
Logger?.LogInformation("The SensorWorker task was canceled.");
|
||||||
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Logger?.LogError($"Unhandled exception in SensorWorker {sensorIdentifier}: {e.Message}");
|
Logger?.LogError($"Unhandled exception in SensorWorker {sensorIdentifier}. {e.GetType()}: {e.Message}");
|
||||||
Logger?.LogDebug(e.StackTrace);
|
Logger?.LogDebug(e.StackTrace);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue