Skip to content

Commit d588e12

Browse files
committed
Added RetentionCleanUpFrequency setting
1 parent 4a1d842 commit d588e12

File tree

9 files changed

+58
-34
lines changed

9 files changed

+58
-34
lines changed

Core/Cleipnir.ResilientFunctions.Tests/InMemoryTests/RFunctionTests/SunshineTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,6 @@ public override Task SecondInvocationOnNullReturningFuncReturnsNullSuccessfully(
4545
);
4646

4747
[TestMethod]
48-
public override Task InvocationModeShouldBeDirectInSunshineScenario()
49-
=> InvocationModeShouldBeDirectInSunshineScenario(FunctionStoreFactory.Create());
48+
public override Task FunctionIsRemovedAfterRetentionPeriod()
49+
=> FunctionIsRemovedAfterRetentionPeriod(FunctionStoreFactory.Create());
5050
}

Core/Cleipnir.ResilientFunctions.Tests/TestTemplates/RFunctionTests/SunshineTests.cs

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
using System;
12
using System.Linq;
23
using System.Threading.Tasks;
4+
using Castle.Components.DictionaryAdapter.Xml;
35
using Cleipnir.ResilientFunctions.CoreRuntime.Invocation;
46
using Cleipnir.ResilientFunctions.Domain;
57
using Cleipnir.ResilientFunctions.Helpers;
@@ -282,24 +284,48 @@ protected async Task SecondInvocationOnNullReturningFuncReturnsNullSuccessfully(
282284
result.ShouldBeNull();
283285
}
284286

285-
public abstract Task InvocationModeShouldBeDirectInSunshineScenario();
286-
protected async Task InvocationModeShouldBeDirectInSunshineScenario(Task<IFunctionStore> storeTask)
287+
public abstract Task FunctionIsRemovedAfterRetentionPeriod();
288+
protected async Task FunctionIsRemovedAfterRetentionPeriod(Task<IFunctionStore> storeTask)
287289
{
288290
var store = await storeTask;
289291
var unhandledExceptionCatcher = new UnhandledExceptionCatcher();
290-
FunctionTypeId functionTypeId = "SomeFunctionType";
291-
using var functionsRegistry = new FunctionsRegistry(store, new Settings(unhandledExceptionCatcher.Catch));
292+
var functionId = TestFunctionId.Create();
293+
{
294+
using var functionsRegistry = new FunctionsRegistry(
295+
store,
296+
new Settings(
297+
unhandledExceptionCatcher.Catch,
298+
enableWatchdogs: false
299+
)
300+
);
301+
302+
var rFunc = functionsRegistry.RegisterAction(
303+
functionId.TypeId,
304+
inner: (string _) => {}
305+
).Invoke;
292306

293-
var syncedInvocationMode = new Synced<InvocationMode>();
294-
var rFunc = functionsRegistry.RegisterAction(
295-
functionTypeId,
296-
(string _) => syncedInvocationMode.Value = InvocationMode.Direct
297-
).Invoke;
307+
await rFunc("hello world", "hello world");
308+
}
298309

299-
await rFunc("hello world", "hello world");
310+
{
311+
using var functionsRegistry = new FunctionsRegistry(
312+
store,
313+
new Settings(
314+
unhandledExceptionCatcher.Catch,
315+
enableWatchdogs: true,
316+
retentionPeriod: TimeSpan.Zero
317+
)
318+
);
319+
320+
functionsRegistry.RegisterAction(
321+
functionId.TypeId,
322+
inner: (string _) => {}
323+
);
324+
325+
await BusyWait.Until(async () => await store.GetFunction(functionId) is null);
326+
}
300327

301-
syncedInvocationMode.Value.ShouldBe(InvocationMode.Direct);
328+
unhandledExceptionCatcher.ThrownExceptions.ShouldBeEmpty();
302329
}
303-
304330
private class State : Domain.WorkflowState {}
305331
}

Core/Cleipnir.ResilientFunctions/CoreRuntime/Invocation/InvocationMode.cs

Lines changed: 0 additions & 7 deletions
This file was deleted.

Core/Cleipnir.ResilientFunctions/CoreRuntime/Watchdogs/RetentionWatchdog.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ internal class RetentionWatchdog
1212
private readonly IFunctionStore _functionStore;
1313
private readonly UnhandledExceptionHandler _unhandledExceptionHandler;
1414
private readonly ShutdownCoordinator _shutdownCoordinator;
15-
private readonly TimeSpan _checkFrequency;
15+
private readonly TimeSpan _cleanUpFrequency;
1616
private readonly TimeSpan _delayStartUp;
1717
private readonly TimeSpan _retentionPeriod;
1818
private readonly FunctionTypeId _functionTypeId;
1919

2020
public RetentionWatchdog(
2121
FunctionTypeId functionTypeId,
2222
IFunctionStore functionStore,
23-
TimeSpan checkFrequency,
23+
TimeSpan cleanUpFrequency,
2424
TimeSpan delayStartUp,
2525
TimeSpan retentionPeriod,
2626
UnhandledExceptionHandler unhandledExceptionHandler,
@@ -30,7 +30,7 @@ public RetentionWatchdog(
3030
_functionStore = functionStore;
3131
_unhandledExceptionHandler = unhandledExceptionHandler;
3232
_shutdownCoordinator = shutdownCoordinator;
33-
_checkFrequency = checkFrequency;
33+
_cleanUpFrequency = cleanUpFrequency;
3434
_delayStartUp = delayStartUp;
3535
_retentionPeriod = retentionPeriod;
3636
}
@@ -58,7 +58,7 @@ public async Task Start()
5858
}
5959

6060
var timeElapsed = DateTime.UtcNow - now;
61-
var delay = (_checkFrequency - timeElapsed).RoundUpToZero();
61+
var delay = (_cleanUpFrequency - timeElapsed).RoundUpToZero();
6262

6363
await Task.Delay(delay);
6464
}

Core/Cleipnir.ResilientFunctions/CoreRuntime/Watchdogs/WatchDogsFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public static void CreateAndStart(
6060
var retentionWatchdog = new RetentionWatchdog(
6161
functionTypeId,
6262
functionStore,
63-
settings.WatchdogCheckFrequency,
63+
settings.RetentionCleanUpFrequency,
6464
settings.DelayStartup,
6565
settings.RetentionPeriod,
6666
settings.UnhandledExceptionHandler,

Core/Cleipnir.ResilientFunctions/Domain/Settings.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public class Settings
1010
{
1111
internal Action<RFunctionException>? UnhandledExceptionHandler { get; }
1212
internal TimeSpan? RetentionPeriod { get; }
13+
internal TimeSpan? RetentionCleanUpFrequency { get; }
1314
internal TimeSpan? LeaseLength { get; }
1415
internal bool? EnableWatchdogs { get; }
1516
internal TimeSpan? WatchdogCheckFrequency { get; }
@@ -23,6 +24,7 @@ public Settings(
2324
Action<RFunctionException>? unhandledExceptionHandler = null,
2425
TimeSpan? retentionPeriod = null,
2526
TimeSpan? leaseLength = null,
27+
TimeSpan? retentionCleanUpFrequency = null,
2628
bool? enableWatchdogs = null,
2729
TimeSpan? watchdogCheckFrequency = null,
2830
TimeSpan? messagesPullFrequency = null,
@@ -33,6 +35,7 @@ public Settings(
3335
{
3436
UnhandledExceptionHandler = unhandledExceptionHandler;
3537
RetentionPeriod = retentionPeriod;
38+
RetentionCleanUpFrequency = retentionCleanUpFrequency;
3639
LeaseLength = leaseLength;
3740
EnableWatchdogs = enableWatchdogs;
3841
WatchdogCheckFrequency = watchdogCheckFrequency;
@@ -47,6 +50,7 @@ public Settings(
4750
public record SettingsWithDefaults(
4851
UnhandledExceptionHandler UnhandledExceptionHandler,
4952
TimeSpan RetentionPeriod,
53+
TimeSpan RetentionCleanUpFrequency,
5054
TimeSpan LeaseLength,
5155
bool EnableWatchdogs,
5256
TimeSpan WatchdogCheckFrequency,
@@ -65,6 +69,7 @@ public SettingsWithDefaults Merge(Settings? child)
6569
? UnhandledExceptionHandler
6670
: new UnhandledExceptionHandler(child.UnhandledExceptionHandler),
6771
child.RetentionPeriod ?? RetentionPeriod,
72+
child.RetentionCleanUpFrequency ?? RetentionCleanUpFrequency,
6873
child.LeaseLength ?? LeaseLength,
6974
child.EnableWatchdogs ?? EnableWatchdogs,
7075
child.WatchdogCheckFrequency ?? WatchdogCheckFrequency,
@@ -80,6 +85,7 @@ public SettingsWithDefaults Merge(Settings? child)
8085
= new(
8186
UnhandledExceptionHandler: new UnhandledExceptionHandler(_ => {}),
8287
RetentionPeriod: TimeSpan.MaxValue,
88+
RetentionCleanUpFrequency: TimeSpan.FromHours(1),
8389
LeaseLength: TimeSpan.FromSeconds(10),
8490
EnableWatchdogs: true,
8591
WatchdogCheckFrequency: TimeSpan.FromSeconds(1),

Stores/MySQL/Cleipnir.ResilientFunctions.MySQL.Tests/RFunctionTests/SunshineTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,6 @@ public override Task SecondInvocationOnNullReturningFuncReturnsNullSuccessfully(
4242
=> SecondInvocationOnNullReturningFuncReturnsNullSuccessfully(FunctionStoreFactory.Create());
4343

4444
[TestMethod]
45-
public override Task InvocationModeShouldBeDirectInSunshineScenario()
46-
=> InvocationModeShouldBeDirectInSunshineScenario(FunctionStoreFactory.Create());
45+
public override Task FunctionIsRemovedAfterRetentionPeriod()
46+
=> FunctionIsRemovedAfterRetentionPeriod(FunctionStoreFactory.Create());
4747
}

Stores/PostgreSQL/Cleipnir.ResilientFunctions.PostgreSQL.Tests/RFunctionTests/SunshineTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ public override Task SunshineScenarioNullReturningFuncWithState()
4141
[TestMethod]
4242
public override Task SecondInvocationOnNullReturningFuncReturnsNullSuccessfully()
4343
=> SecondInvocationOnNullReturningFuncReturnsNullSuccessfully(FunctionStoreFactory.Create());
44-
44+
4545
[TestMethod]
46-
public override Task InvocationModeShouldBeDirectInSunshineScenario()
47-
=> InvocationModeShouldBeDirectInSunshineScenario(FunctionStoreFactory.Create());
46+
public override Task FunctionIsRemovedAfterRetentionPeriod()
47+
=> FunctionIsRemovedAfterRetentionPeriod(FunctionStoreFactory.Create());
4848
}

Stores/SqlServer/Cleipnir.ResilientFunctions.SqlServer.Tests/RFunctionTests/SunshineTests.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ public override Task SunshineScenarioNullReturningFuncWithState()
4242
public override Task SecondInvocationOnNullReturningFuncReturnsNullSuccessfully()
4343
=> SecondInvocationOnNullReturningFuncReturnsNullSuccessfully(FunctionStoreFactory.Create());
4444

45-
4645
[TestMethod]
47-
public override Task InvocationModeShouldBeDirectInSunshineScenario()
48-
=> InvocationModeShouldBeDirectInSunshineScenario(FunctionStoreFactory.Create());
46+
public override Task FunctionIsRemovedAfterRetentionPeriod()
47+
=> FunctionIsRemovedAfterRetentionPeriod(FunctionStoreFactory.Create());
4948
}

0 commit comments

Comments
 (0)