summary refs log tree commit diff
path: root/testFrontend/SafeNSound.FakeUser/RandomAlarmService.cs
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2025-06-03 21:28:05 +0200
committerRory& <root@rory.gay>2025-06-03 21:28:05 +0200
commit784cb47ceb905abacc3a9bd66d5818fb88ea95a4 (patch)
tree0af6e4ca40d8c5a7ea607379cbe9506bd3280e04 /testFrontend/SafeNSound.FakeUser/RandomAlarmService.cs
parentAdd preparation and build instructions (diff)
downloadnodejs-final-assignment-784cb47ceb905abacc3a9bd66d5818fb88ea95a4.tar.xz
testFrontend: add activity for almost all endpoints
Diffstat (limited to 'testFrontend/SafeNSound.FakeUser/RandomAlarmService.cs')
-rw-r--r--testFrontend/SafeNSound.FakeUser/RandomAlarmService.cs13
1 files changed, 8 insertions, 5 deletions
diff --git a/testFrontend/SafeNSound.FakeUser/RandomAlarmService.cs b/testFrontend/SafeNSound.FakeUser/RandomAlarmService.cs

index 7835f89..a2e133f 100644 --- a/testFrontend/SafeNSound.FakeUser/RandomAlarmService.cs +++ b/testFrontend/SafeNSound.FakeUser/RandomAlarmService.cs
@@ -1,20 +1,23 @@ namespace SafeNSound.FakeUser; -public class RandomAlarmService(UserStore userStore): IHostedService { +public class RandomAlarmService(UserStore userStore) : IHostedService { private Task? _listenerTask; private readonly CancellationTokenSource _cts = new(); - + public async Task StartAsync(CancellationToken cancellationToken) { _listenerTask = Run(_cts.Token); } + private static readonly string[] validReasons = ["fall", "toilet"]; + private async Task Run(CancellationToken cancellationToken) { while (!cancellationToken.IsCancellationRequested) { try { var user = userStore.GetRandomUser(); - if (Random.Shared.Next(100) > 90) { + var currentAlarm = await user.Client!.GetAlarm(); + if (currentAlarm is null) { await user.Client!.SetAlarm(new Sdk.AlarmDto { - Reason = "fall" + Reason = Random.Shared.GetItems(validReasons, 1).First() }); } else { @@ -25,7 +28,7 @@ public class RandomAlarmService(UserStore userStore): IHostedService { Console.WriteLine($"Error setting/deleting alarm: {ex.Message}"); } - await Task.Delay(TimeSpan.FromMilliseconds(100), cancellationToken); + await Task.Delay(TimeSpan.FromMilliseconds(250), cancellationToken); } }