Skip to content

Commit 1e1d57f

Browse files
stidsborgclaude
andauthored
Adapt to latest ResilientFunctions API changes (#11)
* Updated Cleipnir.ResilientFunctions to the latest commit * Adapt to ResilientFunctions Settings/EffectId API changes The Settings constructor dropped leaseLength and added replicaHeartbeatFrequency, and EffectId no longer converts implicitly from int. - Options: replace LeaseLength with ReplicaHeartbeatFrequency and pass Settings args by name; also stop dropping UtcNow in Merge - FlowsContainer: rebuild Options by name so no options are dropped - Tests: construct InitialEffect with EffectId via 0.ToEffectId() - Samples: use replicaHeartbeatFrequency instead of leaseLength Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 7ee7b3f commit 1e1d57f

8 files changed

Lines changed: 37 additions & 35 deletions

File tree

Cleipnir.ResilientFunctions

Cleipnir.Tests/Flows/FunctionRegistrationTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ await flows.Run(
3535
param: "SomeParam",
3636
new InitialState(
3737
[new MessageAndIdempotencyKey(new StringMessage("InitialMessageValue"))],
38-
[new InitialEffect(0, "InitialEffectValue")]
38+
[new InitialEffect(0.ToEffectId(), "InitialEffectValue")]
3939
)
4040
);
4141

Cleipnir.Tests/Flows/ParamlessFlowsTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ await flows.Run(
158158
"SomeInstanceId",
159159
new InitialState(
160160
[new MessageAndIdempotencyKey(new StringMessage("InitialMessageValue"))],
161-
[new InitialEffect(0, "InitialEffectValue")]
161+
[new InitialEffect(0.ToEffectId(), "InitialEffectValue")]
162162
)
163163
);
164164

Cleipnir.Tests/Flows/UnitFlowsTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ await flows.Run(
265265
param: "SomeParam",
266266
new InitialState(
267267
[new MessageAndIdempotencyKey(new StringMessage("InitialMessageValue"))],
268-
[new InitialEffect(0, "InitialEffectValue")]
268+
[new InitialEffect(0.ToEffectId(), "InitialEffectValue")]
269269
)
270270
);
271271

Cleipnir/FlowsContainer.cs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,17 @@ public FlowsContainer(IFunctionStore flowStore, IServiceProvider serviceProvider
2727
var logger = serviceProvider.GetRequiredService<ILogger>();
2828
options = new Options(
2929
unhandledExceptionHandler: ex => logger.LogError(ex, "Unhandled exception in Cleipnir"),
30-
options.RetentionPeriod,
31-
options.RetentionCleanUpFrequency,
32-
options.LeaseLength,
33-
options.EnableWatchdogs,
34-
options.WatchdogCheckFrequency,
35-
options.MessagesPullFrequency,
36-
options.MessagesDefaultMaxWaitForCompletion,
37-
options.DelayStartup,
38-
options.MaxParallelRetryInvocations,
39-
options.Serializer
30+
retentionPeriod: options.RetentionPeriod,
31+
retentionCleanUpFrequency: options.RetentionCleanUpFrequency,
32+
enableWatchdogs: options.EnableWatchdogs,
33+
watchdogCheckFrequency: options.WatchdogCheckFrequency,
34+
messagesPullFrequency: options.MessagesPullFrequency,
35+
messagesDefaultMaxWaitForCompletion: options.MessagesDefaultMaxWaitForCompletion,
36+
delayStartup: options.DelayStartup,
37+
maxParallelRetryInvocations: options.MaxParallelRetryInvocations,
38+
serializer: options.Serializer,
39+
utcNow: options.UtcNow,
40+
replicaHeartbeatFrequency: options.ReplicaHeartbeatFrequency
4041
);
4142
}
4243

Cleipnir/Options.cs

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ public class Options
1313
internal Action<FrameworkException>? UnhandledExceptionHandler { get; }
1414
internal TimeSpan? RetentionPeriod { get; }
1515
internal TimeSpan? RetentionCleanUpFrequency { get; }
16-
internal TimeSpan? LeaseLength { get; }
1716
internal bool? EnableWatchdogs { get; }
1817
internal TimeSpan? WatchdogCheckFrequency { get; }
1918
internal TimeSpan? DelayStartup { get; }
@@ -22,14 +21,14 @@ public class Options
2221
internal TimeSpan? MessagesDefaultMaxWaitForCompletion { get; }
2322
internal ISerializer? Serializer { get; }
2423
internal UtcNow? UtcNow { get; }
24+
internal TimeSpan? ReplicaHeartbeatFrequency { get; }
2525

2626
/// <summary>
2727
/// Configuration options for Cleipnir
2828
/// </summary>
2929
/// <param name="unhandledExceptionHandler">Callback handler for unhandled flow exceptions</param>
3030
/// <param name="retentionPeriod">Period to keep completed flows before deletion. Default infinite.</param>
3131
/// <param name="retentionCleanUpFrequency">Retention clean-up check frequency. Default 1 hour when retention period is not infinite.</param>
32-
/// <param name="leaseLength">Flow lease-length. Leases are automatically renewed. Default 60 seconds.</param>
3332
/// <param name="enableWatchdogs">Enable background crashed, interrupted and postponed flow scheduling. Default true.</param>
3433
/// <param name="watchdogCheckFrequency">Check frequency for eligible crashed, interrupted and postponed flows. Default 1 second.</param>
3534
/// <param name="messagesPullFrequency">Pull frequency for active/max-waiting messages. Default: 250ms</param>
@@ -38,24 +37,24 @@ public class Options
3837
/// <param name="maxParallelRetryInvocations">Limit the number of watchdog started invocations. Default: 100.</param>
3938
/// <param name="serializer">Specify custom serializer. Default built-in json-serializer.</param>
4039
/// <param name="utcNow">Provide custom delegate for providing current utc datetime. Default: () => DateTime.UtcNow</param>
40+
/// <param name="replicaHeartbeatFrequency">Heartbeat frequency for replica liveness detection. Default 1 second.</param>
4141
public Options(
4242
Action<FrameworkException>? unhandledExceptionHandler = null,
4343
TimeSpan? retentionPeriod = null,
4444
TimeSpan? retentionCleanUpFrequency = null,
45-
TimeSpan? leaseLength = null,
4645
bool? enableWatchdogs = null,
4746
TimeSpan? watchdogCheckFrequency = null,
4847
TimeSpan? messagesPullFrequency = null,
4948
TimeSpan? messagesDefaultMaxWaitForCompletion = null,
5049
TimeSpan? delayStartup = null,
5150
int? maxParallelRetryInvocations = null,
5251
ISerializer? serializer = null,
53-
UtcNow? utcNow = null
52+
UtcNow? utcNow = null,
53+
TimeSpan? replicaHeartbeatFrequency = null
5454
)
5555
{
5656
UnhandledExceptionHandler = unhandledExceptionHandler;
5757
WatchdogCheckFrequency = watchdogCheckFrequency;
58-
LeaseLength = leaseLength;
5958
RetentionPeriod = retentionPeriod;
6059
RetentionCleanUpFrequency = retentionCleanUpFrequency;
6160
EnableWatchdogs = enableWatchdogs;
@@ -65,6 +64,7 @@ public Options(
6564
MaxParallelRetryInvocations = maxParallelRetryInvocations;
6665
Serializer = serializer;
6766
UtcNow = utcNow;
67+
ReplicaHeartbeatFrequency = replicaHeartbeatFrequency;
6868
}
6969

7070
public Options Merge(Options options)
@@ -73,30 +73,31 @@ public Options Merge(Options options)
7373
UnhandledExceptionHandler ?? options.UnhandledExceptionHandler,
7474
RetentionPeriod ?? options.RetentionPeriod,
7575
RetentionCleanUpFrequency ?? options.RetentionCleanUpFrequency,
76-
LeaseLength ?? options.LeaseLength,
7776
EnableWatchdogs ?? options.EnableWatchdogs,
7877
WatchdogCheckFrequency ?? options.WatchdogCheckFrequency,
7978
MessagesPullFrequency ?? options.MessagesPullFrequency,
8079
MessagesDefaultMaxWaitForCompletion ?? options.MessagesDefaultMaxWaitForCompletion,
8180
DelayStartup ?? options.DelayStartup,
8281
MaxParallelRetryInvocations ?? options.MaxParallelRetryInvocations,
83-
Serializer ?? options.Serializer
82+
Serializer ?? options.Serializer,
83+
UtcNow ?? options.UtcNow,
84+
ReplicaHeartbeatFrequency ?? options.ReplicaHeartbeatFrequency
8485
);
8586
}
8687

8788
internal Settings MapToSettings()
8889
=> new(
89-
UnhandledExceptionHandler,
90-
RetentionPeriod,
91-
RetentionCleanUpFrequency,
92-
LeaseLength,
93-
EnableWatchdogs,
94-
WatchdogCheckFrequency,
95-
MessagesPullFrequency,
96-
MessagesDefaultMaxWaitForCompletion,
97-
DelayStartup,
98-
MaxParallelRetryInvocations,
99-
Serializer,
100-
UtcNow
90+
unhandledExceptionHandler: UnhandledExceptionHandler,
91+
retentionPeriod: RetentionPeriod,
92+
retentionCleanUpFrequency: RetentionCleanUpFrequency,
93+
enableWatchdogs: EnableWatchdogs,
94+
watchdogCheckFrequency: WatchdogCheckFrequency,
95+
messagesPullFrequency: MessagesPullFrequency,
96+
messagesDefaultMaxWaitForCompletion: MessagesDefaultMaxWaitForCompletion,
97+
delayStartup: DelayStartup,
98+
maxParallelRetryInvocations: MaxParallelRetryInvocations,
99+
serializer: Serializer,
100+
utcNow: UtcNow,
101+
replicaHeartbeatFrequency: ReplicaHeartbeatFrequency
101102
);
102103
}

Samples/Cleipnir.Sample.AspNet/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ private static async Task Main(string[] args)
2727
await DatabaseHelper.CreateDatabaseIfNotExists(connectionString); //use to create db initially or clean existing state in database
2828
builder.Services.AddFlows(c => c
2929
.UsePostgresStore(connectionString)
30-
.WithOptions(new Options(leaseLength: TimeSpan.FromSeconds(5)))
30+
.WithOptions(new Options(replicaHeartbeatFrequency: TimeSpan.FromSeconds(5)))
3131
.RegisterFlow<OrderFlow, Order>()
3232
);
3333

Samples/Cleipnir.Sample.Presentation.AspNet/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ private static async Task Main(string[] args)
3232
//await DatabaseHelper.RecreateDatabase(connectionString);
3333
builder.Services.AddFlows(c => c
3434
.UsePostgresStore(connectionString)
35-
.WithOptions(new Options(leaseLength: TimeSpan.FromSeconds(5), messagesDefaultMaxWaitForCompletion: TimeSpan.MaxValue))
35+
.WithOptions(new Options(replicaHeartbeatFrequency: TimeSpan.FromSeconds(5), messagesDefaultMaxWaitForCompletion: TimeSpan.MaxValue))
3636
.RegisterFlow<OrderFlow, Order>()
3737
.RegisterFlow<BatchOrderFlow, List<Order>>()
3838
.RegisterFlow<SingleOrderFlow, Order, TransactionIdAndTrackAndTrace>()

0 commit comments

Comments
 (0)