Skip to content

Commit 52f7f55

Browse files
committed
Update agent to cope with fail/cancel logic
1 parent e3baec6 commit 52f7f55

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

src/IntelOrca.Biohazard.BioRand.Common/IntelOrca.Biohazard.BioRand.Common.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<TargetFramework>netstandard2.0</TargetFramework>
44
<Nullable>enable</Nullable>
55
<LangVersion>12.0</LangVersion>
6-
<Version>1.0.0</Version>
6+
<Version>1.1.0</Version>
77
<Title>BioRand Common Library</Title>
88
<Authors>Ted John</Authors>
99
<Product>$(AssemblyName)</Product>

src/IntelOrca.Biohazard.BioRand.Common/RandomizerAgent.cs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
using System;
2+
using System.Net.Http;
3+
using System.Text;
4+
using System.Text.Json;
5+
using System.Threading;
6+
using System.Threading.Tasks;
7+
18
namespace IntelOrca.Biohazard.BioRand
29
{
310
public class RandomizerAgent
@@ -43,10 +50,16 @@ public async Task RunAsync(CancellationToken ct = default)
4350
{
4451
if (await RegisterAsync())
4552
{
46-
await Task.WhenAny(
47-
RunStatusLoopAsync(ct),
48-
RunProcessLoopAsync(ct));
49-
await UnregisterAsync();
53+
try
54+
{
55+
await Task.WhenAny(
56+
RunStatusLoopAsync(ct),
57+
RunProcessLoopAsync(ct));
58+
}
59+
finally
60+
{
61+
await UnregisterAsync();
62+
}
5063
}
5164
await Task.Delay(RestartTime, ct);
5265
}
@@ -225,10 +238,12 @@ private async Task GenerateRandomizer(QueueResponseItem q)
225238
}
226239
catch (Exception ex)
227240
{
241+
var reason = ex is RandomizerUserException ue ? ue.Message : "An internal error occured generating the randomizer.";
228242
await PostAsync<object>("generator/fail", new
229243
{
230244
Id,
231-
RandoId = q.Id
245+
RandoId = q.Id,
246+
Reason = reason
232247
});
233248
_handler.LogError(ex, "Failed to generate randomizer");
234249
return;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
using System;
2+
3+
namespace IntelOrca.Biohazard.BioRand
4+
{
5+
public class RandomizerUserException(string reason) : Exception(reason)
6+
{
7+
}
8+
}

0 commit comments

Comments
 (0)