-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
VehicleTelemetryEventsConsumer.cs
35 lines (30 loc) · 1.3 KB
/
VehicleTelemetryEventsConsumer.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
namespace HealthCheck;
internal class VehicleTelemetryEventsConsumer(ILogger<VehicleTelemetryEventsConsumer> logger) : IEventConsumer<VehicleTelemetryEvent>
{
public async Task ConsumeAsync(EventContext<VehicleTelemetryEvent> context, CancellationToken cancellationToken)
{
var telemetry = context.Event;
var status = telemetry.VehicleDoorStatus;
if (status is not VehicleDoorStatus.Open and not VehicleDoorStatus.Closed)
{
logger.LogWarning("Vehicle Door status '{VehicleDoorStatus}' is not yet supported", status);
return;
}
var kind = telemetry.VehicleDoorKind;
if (kind is null)
{
logger.LogWarning("Vehicle Door kind '{VehicleDoorKind}' cannot be null", kind);
return;
}
var timestamp = telemetry.Timestamp;
var updateEvt = new VehicleDoorOpenedEvent
{
VehicleId = telemetry.DeviceId,
Kind = kind.Value,
Closed = status is VehicleDoorStatus.Closed ? timestamp : null,
Opened = status is VehicleDoorStatus.Open ? timestamp : null,
};
// the VehicleDoorOpenedEvent on a broadcast bus would notify all subscribers
await context.PublishAsync(updateEvt, cancellationToken: cancellationToken);
}
}