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);
|
||||
}
|
||||
}
|
||||
catch (TaskCanceledException)
|
||||
{
|
||||
_logger?.LogInformation("The TelemetryWorker task was canceled.");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger?.LogError($"Unhandled exception in TelemetryWorker. {e.Message}");
|
||||
|
|
|
@ -33,7 +33,9 @@ namespace NucuCar.Sensors
|
|||
services.AddSingleton<ISensor<HeartbeatSensor>, HeartbeatSensor>();
|
||||
|
||||
// Workers
|
||||
// Telemetry
|
||||
services.AddHostedService<TelemetryWorker>();
|
||||
// Sensors
|
||||
services.AddHostedService<Bme680Worker>();
|
||||
services.AddHostedService<CpuTempWorker>();
|
||||
services.AddHostedService<HeartbeatWorker>();
|
||||
|
|
|
@ -67,9 +67,13 @@ namespace NucuCar.Sensors
|
|||
|
||||
TelemetryPublisher?.UnRegisterTelemeter(Sensor);
|
||||
}
|
||||
catch (TaskCanceledException)
|
||||
{
|
||||
Logger?.LogInformation("The SensorWorker task was canceled.");
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue