Skip to content

Commit f223f06

Browse files
committed
Start and initialize ReplicaWatchdog on FunctionRegistry creation
1 parent a2fab73 commit f223f06

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

Core/Cleipnir.ResilientFunctions.Tests/TestTemplates/FunctionTests/PostponedTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,6 @@ protected async Task PostponedActionIsCompletedByWatchDogAfterCrash(Task<IFuncti
264264
(
265265
crashableStore,
266266
new Settings(
267-
unhandledExceptionHandler.Catch,
268267
leaseLength: TimeSpan.Zero,
269268
enableWatchdogs: false
270269
)

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Threading;
44
using System.Threading.Tasks;
55
using Cleipnir.ResilientFunctions.CoreRuntime.Invocation;
6+
using Cleipnir.ResilientFunctions.Domain;
67
using Cleipnir.ResilientFunctions.Domain.Exceptions;
78
using Cleipnir.ResilientFunctions.Helpers;
89
using Cleipnir.ResilientFunctions.Storage;
@@ -17,7 +18,8 @@ internal class CrashedOrPostponedWatchdog
1718

1819
private readonly TimeSpan _checkFrequency;
1920
private readonly TimeSpan _delayStartUp;
20-
21+
private readonly ClusterInfo _clusterInfo;
22+
2123
private readonly LeasesUpdater _leasesUpdater;
2224

2325
private volatile ImmutableDictionary<StoredType, Tuple<RestartFunction, ScheduleRestartFromWatchdog, AsyncSemaphore>> _flowsDictionary
@@ -31,6 +33,7 @@ public CrashedOrPostponedWatchdog(
3133
IFunctionStore functionStore,
3234
ShutdownCoordinator shutdownCoordinator, UnhandledExceptionHandler unhandledExceptionHandler,
3335
TimeSpan checkFrequency, TimeSpan delayStartUp,
36+
ClusterInfo clusterInfo,
3437
LeasesUpdater leasesUpdater,
3538
UtcNow utcNow)
3639
{
@@ -39,6 +42,7 @@ public CrashedOrPostponedWatchdog(
3942
_unhandledExceptionHandler = unhandledExceptionHandler;
4043
_checkFrequency = checkFrequency;
4144
_delayStartUp = delayStartUp;
45+
_clusterInfo = clusterInfo;
4246
_leasesUpdater = leasesUpdater;
4347
_utcNow = utcNow;
4448
}

Core/Cleipnir.ResilientFunctions/FunctionsRegistry.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ public FunctionsRegistry(IFunctionStore functionStore, Settings? settings = null
4444
_leasesUpdater = new LeasesUpdater(_settings.LeaseLength, _functionStore, _settings.UnhandledExceptionHandler, utcNow);
4545
_ = _leasesUpdater.Start();
4646

47+
ClusterInfo = new ClusterInfo(ReplicaId.NewId());
48+
4749
_timeoutWatchdog = new TimeoutWatchdog(
4850
functionStore.TimeoutStore,
4951
_settings.WatchdogCheckFrequency,
@@ -58,13 +60,14 @@ public FunctionsRegistry(IFunctionStore functionStore, Settings? settings = null
5860
_settings.UnhandledExceptionHandler,
5961
_settings.WatchdogCheckFrequency,
6062
_settings.DelayStartup,
63+
ClusterInfo,
6164
_leasesUpdater,
6265
utcNow
6366
);
64-
65-
ClusterInfo = new ClusterInfo(ReplicaId.NewId());
66-
_replicaWatchdog = new ReplicaWatchdog(ClusterInfo, functionStore, checkFrequency: TimeSpan.FromSeconds(1), _settings.UnhandledExceptionHandler);
6767

68+
_replicaWatchdog = new ReplicaWatchdog(ClusterInfo, functionStore, checkFrequency: TimeSpan.FromSeconds(1), _settings.UnhandledExceptionHandler);
69+
_replicaWatchdog.Initialize().GetAwaiter().GetResult();
70+
_ = _replicaWatchdog.Start();
6871
}
6972

7073
#region Func overloads

0 commit comments

Comments
 (0)