Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions Cleipnir.Tests/Flows/FlowsWithResultTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ public async Task SimpleFlowCompletesSuccessfully()
var flowStore = new InMemoryFunctionStore();
var flowsContainer = new FlowsContainer(
flowStore,
serviceCollection.BuildServiceProvider(),
Options.Default
serviceCollection.BuildServiceProvider()
);

var flows = new SimpleFuncFlows(flowsContainer);
Expand Down Expand Up @@ -67,7 +66,7 @@ public async Task CompletionOfScheduledFlowCanBeAwaited()
var flowsContainer = new FlowsContainer(
flowStore,
serviceCollection.BuildServiceProvider(),
new Options(watchdogCheckFrequency: TimeSpan.FromMilliseconds(100))
new Settings(watchdogCheckFrequency: TimeSpan.FromMilliseconds(100))
);

var flows = new SimpledDelayedFlows(flowsContainer);
Expand Down Expand Up @@ -104,7 +103,7 @@ public async Task EventDrivenFlowCompletesSuccessfully()
var flowsContainer = new FlowsContainer(
flowStore,
serviceCollection.BuildServiceProvider(),
new Options(watchdogCheckFrequency: TimeSpan.FromMilliseconds(100))
new Settings(watchdogCheckFrequency: TimeSpan.FromMilliseconds(100))
);

var flows = new MessageDrivenFuncFlows(flowsContainer);
Expand Down Expand Up @@ -151,8 +150,7 @@ public async Task FailingFlowCompletesWithError()
var flowStore = new InMemoryFunctionStore();
var flowsContainer = new FlowsContainer(
flowStore,
serviceCollection.BuildServiceProvider(),
new Options()
serviceCollection.BuildServiceProvider()
);

var flows = new FailingFuncFlows(flowsContainer);
Expand Down
5 changes: 3 additions & 2 deletions Cleipnir.Tests/Flows/MultipleRegistrationTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Cleipnir.ResilientFunctions.Storage;
using Cleipnir.ResilientFunctions.Domain;
using Microsoft.Extensions.DependencyInjection;
using Shouldly;

Expand All @@ -12,7 +13,7 @@ public void SameFlowTypeWithSameNameCanBeRegisteredSeveralTimes()
{
var serviceCollection = new ServiceCollection();
var store = new InMemoryFunctionStore();
var flowsContainer = new FlowsContainer(store, serviceCollection.BuildServiceProvider(), new Options());
var flowsContainer = new FlowsContainer(store, serviceCollection.BuildServiceProvider());
_ = new TestFlowType1s(flowsContainer);
_ = new TestFlowType1s(flowsContainer);
}
Expand All @@ -22,7 +23,7 @@ public void DifferentFlowTypesWithSameNameCannotBeRegisteredSeveralTimes()
{
var serviceCollection = new ServiceCollection();
var store = new InMemoryFunctionStore();
var flowsContainer = new FlowsContainer(store, serviceCollection.BuildServiceProvider(), new Options());
var flowsContainer = new FlowsContainer(store, serviceCollection.BuildServiceProvider());
_ = new TestFlowType1s(flowsContainer);
Should.Throw<InvalidOperationException>(() =>
new TestFlowType2s(flowsContainer)
Expand Down
4 changes: 2 additions & 2 deletions Cleipnir.Tests/Flows/OptionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public async Task SimpleFlowCompletesSuccessfully()

serviceCollection.AddFlows(c => c
.UseInMemoryStore()
.WithOptions(new Options(
.WithOptions(new Settings(
messagesDefaultMaxWaitForCompletion: TimeSpan.FromDays(1),
watchdogCheckFrequency: TimeSpan.FromMilliseconds(100)
))
Expand Down Expand Up @@ -63,7 +63,7 @@ public async Task FlowNameCanBeSpecifiedFromTheOutside()

serviceCollection.AddFlows(c => c
.UseInMemoryStore(store)
.WithOptions(new Options(
.WithOptions(new Settings(
messagesDefaultMaxWaitForCompletion: TimeSpan.FromDays(1),
watchdogCheckFrequency: TimeSpan.FromMilliseconds(100)
))
Expand Down
8 changes: 3 additions & 5 deletions Cleipnir.Tests/Flows/ParamlessFlowsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ public async Task SimpleFlowCompletesSuccessfully()
var flowStore = new InMemoryFunctionStore();
var flowsContainer = new FlowsContainer(
flowStore,
serviceCollection.BuildServiceProvider(),
Options.Default
serviceCollection.BuildServiceProvider()
);

var flows = new SimpleParamlessFlows(flowsContainer);
Expand Down Expand Up @@ -60,7 +59,7 @@ public async Task EventDrivenFlowCompletesSuccessfully()
var flowsContainer = new FlowsContainer(
flowStore,
serviceCollection.BuildServiceProvider(),
new Options(watchdogCheckFrequency: TimeSpan.FromMilliseconds(100))
new Settings(watchdogCheckFrequency: TimeSpan.FromMilliseconds(100))
);

var flows = new EventDrivenParamlessFlows(flowsContainer);
Expand Down Expand Up @@ -105,8 +104,7 @@ public async Task FailingFlowCompletesWithError()
var flowStore = new InMemoryFunctionStore();
var flowsContainer = new FlowsContainer(
flowStore,
serviceCollection.BuildServiceProvider(),
new Options()
serviceCollection.BuildServiceProvider()
);

var flows = new FailingParamlessFlows(flowsContainer);
Expand Down
14 changes: 5 additions & 9 deletions Cleipnir.Tests/Flows/UnitFlowsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ public async Task SimpleFlowCompletesSuccessfully()
var flowStore = new InMemoryFunctionStore();
var flowsContainer = new FlowsContainer(
flowStore,
serviceCollection.BuildServiceProvider(),
Options.Default
serviceCollection.BuildServiceProvider()
);

var flows = new SimpleUnitFlows(flowsContainer);
Expand Down Expand Up @@ -64,7 +63,7 @@ public async Task EventDrivenFlowCompletesSuccessfully()
var flowsContainer = new FlowsContainer(
flowStore,
serviceCollection.BuildServiceProvider(),
new Options(watchdogCheckFrequency: TimeSpan.FromMilliseconds(100))
new Settings(watchdogCheckFrequency: TimeSpan.FromMilliseconds(100))
);

var flows = new EventDrivenUnitFlows(flowsContainer);
Expand Down Expand Up @@ -110,8 +109,7 @@ public async Task FailingActionFlowCompletesWithError()
var flowStore = new InMemoryFunctionStore();
var flowsContainer = new FlowsContainer(
flowStore,
serviceCollection.BuildServiceProvider(),
new Options()
serviceCollection.BuildServiceProvider()
);

var flows = new FallingUnitActionFlows(flowsContainer);
Expand Down Expand Up @@ -160,8 +158,7 @@ public async Task FailingFuncFlowCompletesWithError()
var flowStore = new InMemoryFunctionStore();
var flowsContainer = new FlowsContainer(
flowStore,
serviceCollection.BuildServiceProvider(),
new Options()
serviceCollection.BuildServiceProvider()
);

var flows = new FallingUnitFuncFlows(flowsContainer);
Expand Down Expand Up @@ -210,8 +207,7 @@ public async Task FailingParamlessFlowCompletesWithError()
var flowStore = new InMemoryFunctionStore();
var flowsContainer = new FlowsContainer(
flowStore,
serviceCollection.BuildServiceProvider(),
new Options()
serviceCollection.BuildServiceProvider()
);

var flows = new FailingUnitParamlessFlows(flowsContainer);
Expand Down
2 changes: 1 addition & 1 deletion Cleipnir.Tests/Flows/UtcNowTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public async Task ProvidedUtcNowDelegateIsUsed()
var flowsContainer = new FlowsContainer(
new InMemoryFunctionStore(),
serviceCollection.BuildServiceProvider(),
new Options(utcNow: () => now, watchdogCheckFrequency: TimeSpan.FromMilliseconds(100))
new Settings(utcNow: () => now, watchdogCheckFrequency: TimeSpan.FromMilliseconds(100))
);

var flows = new Flows<UtcNowTestFlow, DateTime>(nameof(UtcNowTestFlow), flowsContainer);
Expand Down
12 changes: 6 additions & 6 deletions Cleipnir/AspNet/FlowsModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static IServiceCollection AddFlows(this IServiceCollection services, Func
configure(configurator);

if (configurator.OptionsFunc is null)
services.AddSingleton(new Options());
services.AddSingleton(new Settings());
else
services.AddSingleton(configurator.OptionsFunc);

Expand All @@ -37,7 +37,7 @@ public class FlowsConfigurator(IServiceCollection services)
internal bool EnableGracefulShutdown = false;
internal readonly HashSet<Type> FlowsTypes = new();

internal Func<IServiceProvider, Options>? OptionsFunc;
internal Func<IServiceProvider, Settings>? OptionsFunc;
public IServiceCollection Services { get; } = services;

public FlowsConfigurator UseInMemoryStore(InMemoryFunctionStore? store = null)
Expand All @@ -52,10 +52,10 @@ public FlowsConfigurator UseStore(IFunctionStore store)
return this;
}

public FlowsConfigurator WithOptions(Options options)
=> WithOptions(_ => options);
public FlowsConfigurator WithOptions(Func<IServiceProvider, Options> optionsFunc)
public FlowsConfigurator WithOptions(Settings settings)
=> WithOptions(_ => settings);

public FlowsConfigurator WithOptions(Func<IServiceProvider, Settings> optionsFunc)
{
OptionsFunc = optionsFunc;
return this;
Expand Down
10 changes: 5 additions & 5 deletions Cleipnir/FlowOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ public FlowOptions(
MaxParallelRetryInvocations = maxParallelRetryInvocations;
}

public FlowOptions Merge(Options options)
public FlowOptions Merge(Settings settings)
{
return new FlowOptions(
RetentionPeriod ?? options.RetentionPeriod,
EnableWatchdogs ?? options.EnableWatchdogs,
MessagesDefaultMaxWaitForCompletion ?? options.MessagesDefaultMaxWaitForCompletion,
MaxParallelRetryInvocations ?? options.MaxParallelRetryInvocations
RetentionPeriod ?? settings.RetentionPeriod,
EnableWatchdogs ?? settings.EnableWatchdogs,
MessagesDefaultMaxWaitForCompletion ?? settings.MessagesDefaultMaxWaitForCompletion,
MaxParallelRetryInvocations ?? settings.MaxParallelRetryInvocations
);
}

Expand Down
36 changes: 19 additions & 17 deletions Cleipnir/FlowsContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Threading;
using System.Threading.Tasks;
using Cleipnir.ResilientFunctions;
using Cleipnir.ResilientFunctions.Domain;
using Cleipnir.ResilientFunctions.Storage;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
Expand All @@ -18,30 +19,31 @@ public class FlowsContainer : IDisposable

public FunctionsRegistry Functions => FunctionRegistry;

public FlowsContainer(IFunctionStore flowStore, IServiceProvider serviceProvider, Options options)
public FlowsContainer(IFunctionStore flowStore, IServiceProvider serviceProvider, Settings? settings = null)
{
ServiceProvider = serviceProvider;
settings ??= new Settings();

if (options.UnhandledExceptionHandler == null && serviceProvider.GetService<ILogger>() != null)
if (settings.UnhandledExceptionHandler == null && serviceProvider.GetService<ILogger>() != null)
{
var logger = serviceProvider.GetRequiredService<ILogger>();
options = new Options(
settings = new Settings(
unhandledExceptionHandler: ex => logger.LogError(ex, "Unhandled exception in Cleipnir"),
retentionPeriod: options.RetentionPeriod,
retentionCleanUpFrequency: options.RetentionCleanUpFrequency,
enableWatchdogs: options.EnableWatchdogs,
watchdogCheckFrequency: options.WatchdogCheckFrequency,
messagesPullFrequency: options.MessagesPullFrequency,
messagesDefaultMaxWaitForCompletion: options.MessagesDefaultMaxWaitForCompletion,
delayStartup: options.DelayStartup,
maxParallelRetryInvocations: options.MaxParallelRetryInvocations,
serializer: options.Serializer,
utcNow: options.UtcNow,
replicaHeartbeatFrequency: options.ReplicaHeartbeatFrequency
retentionPeriod: settings.RetentionPeriod,
retentionCleanUpFrequency: settings.RetentionCleanUpFrequency,
enableWatchdogs: settings.EnableWatchdogs,
watchdogCheckFrequency: settings.WatchdogCheckFrequency,
messagesPullFrequency: settings.MessagesPullFrequency,
messagesDefaultMaxWaitForCompletion: settings.MessagesDefaultMaxWaitForCompletion,
delayStartup: settings.DelayStartup,
maxParallelRetryInvocations: settings.MaxParallelRetryInvocations,
serializer: settings.Serializer,
utcNow: settings.UtcNow,
replicaHeartbeatFrequency: settings.ReplicaHeartbeatFrequency
);
}

FunctionRegistry = new FunctionsRegistry(flowStore, options.MapToSettings());
FunctionRegistry = new FunctionsRegistry(flowStore, settings);
}

internal void EnsureNoExistingRegistration(string flowName, Type flowType)
Expand Down Expand Up @@ -77,10 +79,10 @@ public Flows<TFlow, TParam, TResult> RegisterAnonymousFlow<TFlow, TParam, TResul
public static FlowsContainer Create(
IServiceProvider? serviceProvider = null,
IFunctionStore? functionStore = null,
Options? options = null)
Settings? settings = null)
=> new(
functionStore ?? new InMemoryFunctionStore(),
serviceProvider ?? new ServiceCollection().BuildServiceProvider(),
options ?? Options.Default
settings ?? new Settings()
);
}
103 changes: 0 additions & 103 deletions Cleipnir/Options.cs

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ var testOrder = new Order("MK-54321", CustomerId: Guid.NewGuid(), ProductIds: [G
await flows.Run(
instanceId: testOrder.OrderId,
testOrder,
new InitialState(Messages: [], Effects: [new InitialEffect(Id: 0, Value: transactionId, Alias: "TransactionId")])
new InitialState(Messages: [], Effects: [new InitialEffect(Id: 0.ToEffectId(), Value: transactionId, Alias: "TransactionId")])
);

Assert.AreEqual(transactionId, usedTransactionId);
Expand Down
Loading