Skip to content

Commit 8687c57

Browse files
committed
Introduce and using LocalSettings
1 parent 643b902 commit 8687c57

File tree

8 files changed

+69
-45
lines changed

8 files changed

+69
-45
lines changed

Core/Cleipnir.ResilientFunctions.Tests/InMemoryTests/RegistrationTests/RActionWithStateRegistrationTests.cs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class RActionWithStateRegistrationTests
1818
[TestMethod]
1919
public async Task ConstructedFuncInvokeCanBeCreatedAndInvoked()
2020
{
21-
using var rFunctions = CreateRFunctions();
21+
using var rFunctions = new FunctionsRegistry(new InMemoryFunctionStore());
2222
var rAction = rFunctions
2323
.RegisterAction<string>(
2424
_flowType,
@@ -32,23 +32,16 @@ public async Task ConstructedFuncInvokeCanBeCreatedAndInvoked()
3232
[TestMethod]
3333
public async Task ConstructedFuncWithCustomSerializerCanBeCreatedAndInvoked()
3434
{
35-
using var rFunctions = CreateRFunctions();
3635
var serializer = new Serializer();
37-
var rAction = rFunctions
38-
.RegisterAction<string>(
39-
_flowType,
40-
InnerAction,
41-
new Settings(serializer: serializer)
42-
)
43-
.Invoke;
36+
using var rFunctions = new FunctionsRegistry(new InMemoryFunctionStore(), new Settings(serializer: serializer));
37+
var rAction = rFunctions.RegisterAction<string>(_flowType, InnerAction).Invoke;
4438

4539
await rAction(flowInstance, "hello world");
4640
serializer.Invoked.ShouldBeTrue();
4741
}
4842

4943
private async Task InnerAction(string param) => await Task.CompletedTask;
50-
private FunctionsRegistry CreateRFunctions() => new(new InMemoryFunctionStore());
51-
44+
5245
private class Serializer : ISerializer
5346
{
5447
public bool Invoked { get; set; }

Core/Cleipnir.ResilientFunctions.Tests/InMemoryTests/RegistrationTests/RFuncRegistrationTests.cs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class RFuncRegistrationTests
1717
[TestMethod]
1818
public async Task ConstructedFuncInvokeCanBeCreatedAndInvoked()
1919
{
20-
using var rFunctions = CreateRFunctions();
20+
using var rFunctions = new FunctionsRegistry(new InMemoryFunctionStore());
2121
var rFunc = rFunctions
2222
.RegisterFunc<string, string>(
2323
_flowType,
@@ -32,15 +32,10 @@ public async Task ConstructedFuncInvokeCanBeCreatedAndInvoked()
3232
[TestMethod]
3333
public async Task ConstructedFuncWithCustomSerializerCanBeCreatedAndInvoked()
3434
{
35-
using var rFunctions = CreateRFunctions();
3635
var serializer = new Serializer();
37-
var rFunc = rFunctions
38-
.RegisterFunc<string, string>(
39-
_flowType,
40-
InnerFunc,
41-
new Settings(serializer: serializer)
42-
)
43-
.Invoke;
36+
using var rFunctions = new FunctionsRegistry(new InMemoryFunctionStore(), new Settings(serializer: serializer));
37+
38+
var rFunc = rFunctions.RegisterFunc<string, string>(_flowType, InnerFunc).Invoke;
4439

4540
var result = await rFunc(flowInstance, "hello world");
4641
result.ShouldBe("HELLO WORLD");
@@ -52,7 +47,6 @@ private async Task<string> InnerFunc(string param)
5247
await Task.CompletedTask;
5348
return param.ToUpper();
5449
}
55-
private FunctionsRegistry CreateRFunctions() => new(new InMemoryFunctionStore());
5650

5751
private class Serializer : ISerializer
5852
{

Core/Cleipnir.ResilientFunctions.Tests/InMemoryTests/RegistrationTests/RFuncWithStateRegistrationTests.cs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,13 @@ public async Task ConstructedFuncInvokeCanBeCreatedAndInvoked()
3232
[TestMethod]
3333
public async Task ConstructedFuncWithCustomSerializerCanBeCreatedAndInvoked()
3434
{
35-
using var rFunctions = CreateRFunctions();
3635
var serializer = new Serializer();
37-
var rFunc = rFunctions
38-
.RegisterFunc<string, string>(
39-
_flowType,
40-
InnerFunc,
41-
new Settings(serializer: serializer)
42-
)
43-
.Invoke;
36+
using var rFunctions = new FunctionsRegistry(
37+
new InMemoryFunctionStore(),
38+
settings: new Settings(serializer: serializer)
39+
);
40+
41+
var rFunc = rFunctions.RegisterFunc<string, string>(_flowType, InnerFunc).Invoke;
4442

4543
var result = await rFunc(flowInstance, "hello world");
4644
result.ShouldBe("HELLO WORLD");

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,13 +297,13 @@ protected async Task ParamlessInstanceIsStartedByMessage(Task<IFunctionStore> st
297297

298298
var registration = functionsRegistry.RegisterParamless(
299299
flowType,
300-
inner: async (Workflow workflow) =>
300+
inner: async (workflow) =>
301301
{
302302
var someMessage = await workflow.Messages.FirstOfType<SomeMessage>();
303303
syncedValue.Value = someMessage.Value;
304304
syncedFlag.Raise();
305305
},
306-
new Settings(
306+
new LocalSettings(
307307
messagesDefaultMaxWaitForCompletion: TimeSpan.MaxValue
308308
)
309309
);
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System;
2+
using Cleipnir.ResilientFunctions.CoreRuntime;
3+
using Cleipnir.ResilientFunctions.CoreRuntime.Serialization;
4+
using Cleipnir.ResilientFunctions.Domain.Exceptions;
5+
6+
namespace Cleipnir.ResilientFunctions.Domain;
7+
8+
public class LocalSettings
9+
{
10+
internal TimeSpan? RetentionPeriod { get; }
11+
internal bool? EnableWatchdogs { get; }
12+
internal int? MaxParallelRetryInvocations { get; }
13+
public TimeSpan? MessagesDefaultMaxWaitForCompletion { get; }
14+
15+
public LocalSettings(
16+
TimeSpan? retentionPeriod = null,
17+
bool? enableWatchdogs = null,
18+
TimeSpan? messagesDefaultMaxWaitForCompletion = null,
19+
int? maxParallelRetryInvocations = null)
20+
{
21+
RetentionPeriod = retentionPeriod;
22+
EnableWatchdogs = enableWatchdogs;
23+
MaxParallelRetryInvocations = maxParallelRetryInvocations;
24+
MessagesDefaultMaxWaitForCompletion = messagesDefaultMaxWaitForCompletion;
25+
}
26+
}

Core/Cleipnir.ResilientFunctions/Domain/Settings.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,19 @@ public SettingsWithDefaults Merge(Settings? child)
7979
child.Serializer ?? Serializer
8080
);
8181
}
82+
83+
public SettingsWithDefaults Merge(LocalSettings? child)
84+
{
85+
if (child == null) return this;
86+
87+
return this with
88+
{
89+
RetentionPeriod = child.RetentionPeriod ?? RetentionPeriod,
90+
EnableWatchdogs = child.EnableWatchdogs ?? EnableWatchdogs,
91+
MessagesDefaultMaxWaitForCompletion = child.MessagesDefaultMaxWaitForCompletion ?? MessagesDefaultMaxWaitForCompletion,
92+
MaxParallelRetryInvocations = child.MaxParallelRetryInvocations ?? MaxParallelRetryInvocations
93+
};
94+
}
8295

8396
public static SettingsWithDefaults Default { get; }
8497
= new(

Core/Cleipnir.ResilientFunctions/FunctionsRegistry.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public FunctionsRegistry(IFunctionStore functionStore, Settings? settings = null
6060
public FuncRegistration<TParam, TReturn> RegisterFunc<TParam, TReturn>(
6161
FlowType flowType,
6262
Func<TParam, Task<TReturn>> inner,
63-
Settings? settings = null
63+
LocalSettings? settings = null
6464
) where TParam : notnull => RegisterFunc(
6565
flowType,
6666
InnerToAsyncResultAdapters.ToInnerFuncWithTaskResultReturn(inner),
@@ -71,7 +71,7 @@ public FuncRegistration<TParam, TReturn> RegisterFunc<TParam, TReturn>(
7171
public FuncRegistration<TParam, TReturn> RegisterFunc<TParam, TReturn>(
7272
FlowType flowType,
7373
Func<TParam, Workflow, Task<TReturn>> inner,
74-
Settings? settings = null
74+
LocalSettings? settings = null
7575
) where TParam : notnull => RegisterFunc(
7676
flowType,
7777
InnerToAsyncResultAdapters.ToInnerFuncWithTaskResultReturn(inner),
@@ -82,7 +82,7 @@ public FuncRegistration<TParam, TReturn> RegisterFunc<TParam, TReturn>(
8282
public FuncRegistration<TParam, TReturn> RegisterFunc<TParam, TReturn>(
8383
FlowType flowType,
8484
Func<TParam, Task<Result<TReturn>>> inner,
85-
Settings? settings = null
85+
LocalSettings? settings = null
8686
) where TParam : notnull
8787
=> RegisterFunc(
8888
flowType,
@@ -97,7 +97,7 @@ public FuncRegistration<TParam, TReturn> RegisterFunc<TParam, TReturn>(
9797
public ActionRegistration<TParam> RegisterAction<TParam>(
9898
FlowType flowType,
9999
Func<TParam, Task> inner,
100-
Settings? settings = null
100+
LocalSettings? settings = null
101101
) where TParam : notnull
102102
=> RegisterAction(
103103
flowType,
@@ -109,7 +109,7 @@ public ActionRegistration<TParam> RegisterAction<TParam>(
109109
public ActionRegistration<TParam> RegisterAction<TParam>(
110110
FlowType flowType,
111111
Func<TParam, Workflow, Task> inner,
112-
Settings? settings = null
112+
LocalSettings? settings = null
113113
) where TParam : notnull
114114
=> RegisterAction(
115115
flowType,
@@ -121,7 +121,7 @@ public ActionRegistration<TParam> RegisterAction<TParam>(
121121
public ActionRegistration<TParam> RegisterAction<TParam>(
122122
FlowType flowType,
123123
Func<TParam, Task<Result<Unit>>> inner,
124-
Settings? settings = null
124+
LocalSettings? settings = null
125125
) where TParam : notnull
126126
=> RegisterAction(
127127
flowType,
@@ -137,7 +137,7 @@ public ActionRegistration<TParam> RegisterAction<TParam>(
137137
public ParamlessRegistration RegisterParamless(
138138
FlowType flowType,
139139
Func<Task<Result<Unit>>> inner,
140-
Settings? settings = null
140+
LocalSettings? settings = null
141141
) => RegisterParamless(
142142
flowType,
143143
InnerToAsyncResultAdapters.ToInnerParamlessWithTaskResultReturn(inner),
@@ -147,7 +147,7 @@ public ParamlessRegistration RegisterParamless(
147147
public ParamlessRegistration RegisterParamless(
148148
FlowType flowType,
149149
Func<Workflow, Task<Result<Unit>>> inner,
150-
Settings? settings = null
150+
LocalSettings? settings = null
151151
) => RegisterParamless(
152152
flowType,
153153
InnerToAsyncResultAdapters.ToInnerParamlessWithTaskResultReturn(inner),
@@ -157,7 +157,7 @@ public ParamlessRegistration RegisterParamless(
157157
public ParamlessRegistration RegisterParamless(
158158
FlowType flowType,
159159
Func<Task> inner,
160-
Settings? settings = null
160+
LocalSettings? settings = null
161161
) => RegisterParamless(
162162
flowType,
163163
InnerToAsyncResultAdapters.ToInnerParamlessWithTaskResultReturn(inner),
@@ -167,7 +167,7 @@ public ParamlessRegistration RegisterParamless(
167167
public ParamlessRegistration RegisterParamless(
168168
FlowType flowType,
169169
Func<Workflow, Task> inner,
170-
Settings? settings = null
170+
LocalSettings? settings = null
171171
) => RegisterParamless(
172172
flowType,
173173
InnerToAsyncResultAdapters.ToInnerParamlessWithTaskResultReturn(inner),
@@ -180,7 +180,7 @@ public ParamlessRegistration RegisterParamless(
180180
public FuncRegistration<TParam, TReturn> RegisterFunc<TParam, TReturn>(
181181
FlowType flowType,
182182
Func<TParam, Workflow, Task<Result<TReturn>>> inner,
183-
Settings? settings = null
183+
LocalSettings? settings = null
184184
) where TParam : notnull
185185
{
186186
if (_disposed)
@@ -266,7 +266,7 @@ public FuncRegistration<TParam, TReturn> RegisterFunc<TParam, TReturn>(
266266
private ParamlessRegistration RegisterParamless(
267267
FlowType flowType,
268268
Func<Unit, Workflow, Task<Result<Unit>>> inner,
269-
Settings? settings = null
269+
LocalSettings? settings = null
270270
)
271271
{
272272
if (_disposed)
@@ -352,7 +352,7 @@ private ParamlessRegistration RegisterParamless(
352352
public ActionRegistration<TParam> RegisterAction<TParam>(
353353
FlowType flowType,
354354
Func<TParam, Workflow, Task<Result<Unit>>> inner,
355-
Settings? settings = null
355+
LocalSettings? settings = null
356356
) where TParam : notnull
357357
{
358358
if (_disposed)

Samples/Sample.OrderProcessing/Messaging/Do.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public static async Task Execute(FunctionsRegistry functionsRegistry)
1616
var rAction = functionsRegistry.RegisterAction<Order>(
1717
"OrderProcessorMessaging",
1818
orderProcessor.Execute,
19-
new Settings(messagesDefaultMaxWaitForCompletion: TimeSpan.FromMinutes(1))
19+
new LocalSettings(messagesDefaultMaxWaitForCompletion: TimeSpan.FromMinutes(1))
2020
);
2121

2222
messageBroker.Subscribe(async msg =>

0 commit comments

Comments
 (0)