Skip to content

Commit

Permalink
Upgraded to ResilientFunctions latest commit
Browse files Browse the repository at this point in the history
  • Loading branch information
stidsborg committed Jul 6, 2024
1 parent b3a1cf1 commit f7a298d
Show file tree
Hide file tree
Showing 20 changed files with 42 additions and 37 deletions.
2 changes: 1 addition & 1 deletion Cleipnir.Flows.Tests/Flows/FlowsWithResultTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public class MessageDrivenFuncFlow : Flow<string, int>
{
public override async Task<int> Run(string param)
{
var next = await Messages.FirstOfType<int>();
var next = await Messages.FirstOfType<int>(maxWait: TimeSpan.MaxValue);
return next;
}
}
Expand Down
22 changes: 11 additions & 11 deletions Cleipnir.Flows.Tests/Flows/FlowsWithStateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@ public async Task ParamlessFlowWithStateCanBeFetchedAfterExecution()
controlPanel.Status.ShouldBe(Status.Succeeded);
}

public class ParamlessFlowWithState : Flow, IHaveState<ParamlessFlowWithState.FlowState>
public class ParamlessFlowWithState : Flow, IHaveState<ParamlessFlowWithState.WorkflowState>
{
public required FlowState State { get; init; }
public required WorkflowState State { get; init; }

public override Task Run()
{
State.Boolean = true;
return Task.CompletedTask;
}

public class FlowState : WorkflowState
public class WorkflowState : FlowState
{
public bool Boolean { get; set; }
}
Expand Down Expand Up @@ -73,22 +73,22 @@ public async Task ActionFlowWithStateCanBeFetchedAfterExecution()
controlPanel.ShouldNotBeNull();
controlPanel.Status.ShouldBe(Status.Succeeded);

var flowState = controlPanel.States.Get<FuncFlowWithState.FlowState>();
var flowState = controlPanel.States.Get<FuncFlowWithState.WorkflowState>();
flowState.ShouldNotBeNull();
flowState.Value.ShouldBe("someParameter");
}

public class ActionFlowWithState : Flow<string>, IHaveState<ActionFlowWithState.FlowState>
public class ActionFlowWithState : Flow<string>, IHaveState<ActionFlowWithState.WorkflowState>
{
public required FlowState State { get; init; }
public required WorkflowState State { get; init; }

public override Task Run(string param)
{
State.Value = param;
return Task.CompletedTask;
}

public class FlowState : WorkflowState
public class WorkflowState : FlowState
{
public string Value { get; set; } = "";
}
Expand Down Expand Up @@ -119,22 +119,22 @@ public async Task FuncFlowWithStateCanBeFetchedAfterExecution()
controlPanel.Result.ShouldBe("someParameter");
controlPanel.Status.ShouldBe(Status.Succeeded);

var flowState = controlPanel.States.Get<FuncFlowWithState.FlowState>();
var flowState = controlPanel.States.Get<FuncFlowWithState.WorkflowState>();
flowState.ShouldNotBeNull();
flowState.Value.ShouldBe("someParameter");
}

public class FuncFlowWithState : Flow<string, string>, IHaveState<FuncFlowWithState.FlowState>
public class FuncFlowWithState : Flow<string, string>, IHaveState<FuncFlowWithState.WorkflowState>
{
public required FlowState State { get; init; }
public required WorkflowState State { get; init; }

public override Task<string> Run(string param)
{
State.Value = param;
return Task.FromResult(param);
}

public class FlowState : WorkflowState
public class WorkflowState : FlowState
{
public string Value { get; set; } = "";
}
Expand Down
2 changes: 1 addition & 1 deletion Cleipnir.Flows.Tests/Flows/ParamlessFlowsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public class EventDrivenParamlessFlow : Flow
{
public override async Task Run()
{
await Messages.FirstOfType<int>();
await Messages.FirstOfType<int>(maxWait: TimeSpan.MaxValue);
}
}

Expand Down
2 changes: 1 addition & 1 deletion Cleipnir.Flows.Tests/Flows/UnitFlowsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public class EventDrivenUnitFlow : Flow<string>
{
public override async Task Run(string param)
{
await Messages.FirstOfType<int>();
await Messages.FirstOfType<int>(maxWait: TimeSpan.MaxValue);
}
}

Expand Down
6 changes: 3 additions & 3 deletions Cleipnir.Flows/Flows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public Flows(string flowName, FlowsContainer flowsContainer) : base(flowsContain
return controlPanel;
}

protected Task<TState?> GetState<TState>(string functionInstanceId) where TState : WorkflowState, new()
protected Task<TState?> GetState<TState>(string functionInstanceId) where TState : FlowState, new()
=> _registration.GetState<TState>(functionInstanceId);

public MessageWriter MessageWriter(string instanceId)
Expand Down Expand Up @@ -168,7 +168,7 @@ public Flows(string flowName, FlowsContainer flowsContainer) : base(flowsContain
return controlPanel;
}

protected Task<TState?> GetState<TState>(string functionInstanceId) where TState : WorkflowState, new()
protected Task<TState?> GetState<TState>(string functionInstanceId) where TState : FlowState, new()
=> _registration.GetState<TState>(functionInstanceId);

public MessageWriter MessageWriter(string instanceId)
Expand Down Expand Up @@ -233,6 +233,6 @@ public Task ScheduleIn(string functionInstanceId,
TimeSpan delay
) => _registration.ScheduleIn(functionInstanceId, param, delay);

protected Task<TState?> GetState<TState>(string functionInstanceId) where TState : WorkflowState, new()
protected Task<TState?> GetState<TState>(string functionInstanceId) where TState : FlowState, new()
=> _registration.GetState<TState>(functionInstanceId);
}
1 change: 1 addition & 0 deletions Cleipnir.Flows/FlowsContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public FlowsContainer(IFunctionStore flowStore, IServiceProvider serviceProvider
options.EnableWatchdogs,
options.WatchdogCheckFrequency,
options.MessagesPullFrequency,
options.MessagesDefaultMaxWaitForCompletion,
options.DelayStartup,
options.MaxParallelRetryInvocations,
options.Serializer
Expand Down
2 changes: 1 addition & 1 deletion Cleipnir.Flows/IHaveState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Cleipnir.Flows;

public interface IHaveState<TState> where TState : WorkflowState, new()
public interface IHaveState<TState> where TState : FlowState, new()
{
public TState State { get; init; }
}
4 changes: 4 additions & 0 deletions Cleipnir.Flows/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class Options
internal TimeSpan? DelayStartup { get; }
internal int? MaxParallelRetryInvocations { get; }
internal TimeSpan? MessagesPullFrequency { get; }
internal TimeSpan? MessagesDefaultMaxWaitForCompletion { get; }
internal ISerializer? Serializer { get; }
internal IEnumerable<RoutingInformation>? Routes { get; }
internal List<MiddlewareInstanceOrType> Middlewares { get; } = new();
Expand All @@ -32,6 +33,7 @@ public Options(
bool? enableWatchdogs = null,
TimeSpan? watchdogCheckFrequency = null,
TimeSpan? messagesPullFrequency = null,
TimeSpan? messagesDefaultMaxWaitForCompletion = null,
TimeSpan? delayStartup = null,
int? maxParallelRetryInvocations = null,
ISerializer? serializer = null,
Expand All @@ -45,6 +47,7 @@ public Options(
RetentionCleanUpFrequency = retentionCleanUpFrequency;
EnableWatchdogs = enableWatchdogs;
MessagesPullFrequency = messagesPullFrequency;
MessagesDefaultMaxWaitForCompletion = messagesDefaultMaxWaitForCompletion;
DelayStartup = delayStartup;
MaxParallelRetryInvocations = maxParallelRetryInvocations;
Serializer = serializer;
Expand Down Expand Up @@ -72,6 +75,7 @@ internal Settings MapToRFunctionsSettings()
EnableWatchdogs,
WatchdogCheckFrequency,
MessagesPullFrequency,
MessagesDefaultMaxWaitForCompletion,
DelayStartup,
MaxParallelRetryInvocations,
Serializer,
Expand Down
2 changes: 1 addition & 1 deletion Cleipnir.ResilientFunctions
Submodule Cleipnir.ResilientFunctions updated 57 files
+2 −2 Core/Cleipnir.ResilientFunctions.Tests/InMemoryTests/RegistrationTests/RActionWithStateRegistrationTests.cs
+2 −2 Core/Cleipnir.ResilientFunctions.Tests/InMemoryTests/RegistrationTests/RFuncRegistrationTests.cs
+2 −2 Core/Cleipnir.ResilientFunctions.Tests/InMemoryTests/RegistrationTests/RFuncWithStateRegistrationTests.cs
+1 −1 Core/Cleipnir.ResilientFunctions.Tests/InMemoryTests/SerializationTests.cs
+3 −2 Core/Cleipnir.ResilientFunctions.Tests/Messaging/TestTemplates/CustomMessageSerializerTests.cs
+9 −2 Core/Cleipnir.ResilientFunctions.Tests/Messaging/TestTemplates/MessagesTests.cs
+19 −19 Core/Cleipnir.ResilientFunctions.Tests/ReactiveTests/LeafOperatorsTests.cs
+3 −3 Core/Cleipnir.ResilientFunctions.Tests/ReactiveTests/SuspensionTests.cs
+2 −2 Core/Cleipnir.ResilientFunctions.Tests/TestTemplates/RFunctionTests/ControlPanelTests.cs
+1 −1 Core/Cleipnir.ResilientFunctions.Tests/TestTemplates/RFunctionTests/CrashedTests.cs
+1 −1 Core/Cleipnir.ResilientFunctions.Tests/TestTemplates/RFunctionTests/FailedTests.cs
+7 −4 Core/Cleipnir.ResilientFunctions.Tests/TestTemplates/RFunctionTests/MessagingTests.cs
+2 −5 Core/Cleipnir.ResilientFunctions.Tests/TestTemplates/RFunctionTests/PostponedTests.cs
+11 −7 Core/Cleipnir.ResilientFunctions.Tests/TestTemplates/RFunctionTests/RoutingTests.cs
+1 −1 Core/Cleipnir.ResilientFunctions.Tests/TestTemplates/RFunctionTests/StateTests.cs
+1 −1 Core/Cleipnir.ResilientFunctions.Tests/TestTemplates/RFunctionTests/SunshineTests.cs
+5 −6 Core/Cleipnir.ResilientFunctions.Tests/TestTemplates/RFunctionTests/SuspensionTests.cs
+2 −1 Core/Cleipnir.ResilientFunctions.Tests/TestTemplates/RFunctionTests/TimeoutTests.cs
+1 −1 Core/Cleipnir.ResilientFunctions.Tests/TestTemplates/ResilientFunctionStateTests.cs
+1 −1 Core/Cleipnir.ResilientFunctions.Tests/TestTemplates/StoreCrudTests.cs
+1 −1 Core/Cleipnir.ResilientFunctions.Tests/TestTemplates/StoreTests.cs
+9 −9 Core/Cleipnir.ResilientFunctions.Tests/TestTemplates/WatchDogsTests/WatchdogCompoundTests.cs
+1 −1 Core/Cleipnir.ResilientFunctions.Tests/Utils/EmptyState.cs
+1 −1 Core/Cleipnir.ResilientFunctions.Tests/Utils/ListState.cs
+1 −1 Core/Cleipnir.ResilientFunctions/ActionRegistration.cs
+2 −1 Core/Cleipnir.ResilientFunctions/CoreRuntime/Invocation/InvocationHelper.cs
+2 −2 Core/Cleipnir.ResilientFunctions/CoreRuntime/ParameterSerialization/DefaultSerializer.cs
+2 −2 Core/Cleipnir.ResilientFunctions/CoreRuntime/ParameterSerialization/ErrorHandlingDecorator.cs
+2 −2 Core/Cleipnir.ResilientFunctions/CoreRuntime/ParameterSerialization/ISerializer.cs
+5 −5 Core/Cleipnir.ResilientFunctions/Domain/ExistingStates.cs
+3 −3 Core/Cleipnir.ResilientFunctions/Domain/FlowState.cs
+6 −0 Core/Cleipnir.ResilientFunctions/Domain/Settings.cs
+2 −2 Core/Cleipnir.ResilientFunctions/Domain/StateFetcher.cs
+6 −6 Core/Cleipnir.ResilientFunctions/Domain/States.cs
+1 −1 Core/Cleipnir.ResilientFunctions/FuncRegistration.cs
+0 −1 Core/Cleipnir.ResilientFunctions/Messaging/Messages.cs
+2 −0 Core/Cleipnir.ResilientFunctions/Messaging/MessagesPullerAndEmitter.cs
+1 −1 Core/Cleipnir.ResilientFunctions/ParamlessRegistration.cs
+44 −115 Core/Cleipnir.ResilientFunctions/Reactive/Extensions/LeafOperators.cs
+1 −0 Core/Cleipnir.ResilientFunctions/Reactive/ISubscription.cs
+3 −3 Core/Cleipnir.ResilientFunctions/Reactive/Operators/BufferOperator.cs
+2 −2 Core/Cleipnir.ResilientFunctions/Reactive/Operators/CustomOperator.cs
+3 −4 Core/Cleipnir.ResilientFunctions/Reactive/Operators/TimeoutOperator.cs
+10 −2 Core/Cleipnir.ResilientFunctions/Reactive/Origin/Source.cs
+5 −2 Core/Cleipnir.ResilientFunctions/Reactive/Origin/SubscriptionGroup.cs
+7 −5 README.md
+1 −1 Samples/Sample.ConsoleApp/EmailOffers/MailSenderSaga.cs
+2 −2 Samples/Sample.ConsoleApp/Engagement/EngagementReminderSaga.cs
+1 −1 Samples/Sample.ConsoleApp/LoanApproval/MessagingApproach/ApproveLoan.cs
+1 −1 Samples/Sample.ConsoleApp/LoyaltyPoints/LoyaltyPointsFlow.cs
+1 −1 Samples/Sample.ConsoleApp/Sample.ConsoleApp.csproj
+2 −2 Samples/Sample.ConsoleApp/SmsVerification/SmsVerificationFlow.cs
+1 −1 Samples/Sample.ConsoleApp/Subscription/SubscriptionSaga.cs
+1 −1 Samples/Sample.ConsoleApp/SupportTicket/Saga.cs
+1 −1 Samples/Sample.ConsoleApp/WorkDistribution/ProcessOrders.cs
+1 −1 Samples/Sample.OrderProcessing/Messaging/OrderProcessor.cs
+1 −1 Stores/StressTests/StressTests/SuspensionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

namespace Cleipnir.Flows.Sample.Presentation.C_NewsletterSender.Solution;

public class NewsletterFlow : Flow<MailAndRecipients>, IHaveState<NewsletterFlow.FlowState>
public class NewsletterFlow : Flow<MailAndRecipients>, IHaveState<NewsletterFlow.NewsletterState>
{
public required FlowState State { get; init; }
public required NewsletterState State { get; init; }

public override async Task Run(MailAndRecipients mailAndRecipients)
{
Expand All @@ -31,7 +31,7 @@ public override async Task Run(MailAndRecipients mailAndRecipients)
}
}

public class FlowState : WorkflowState
public class NewsletterState : FlowState
{
public int AtRecipient { get; set; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public override async Task Run(LoanApplication loanApplication)
.OfType<CreditCheckOutcome>()
.Take(3)
.TakeUntilTimeout("Timeout", TimeSpan.FromMinutes(15))
.SuspendUntilCompletion();
.Completion();

if (outcomes.Count < 2)
await MessageBroker.Send(new LoanApplicationRejected(loanApplication));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public override async Task Run(string customerEmail)
var emailVerifiedOption = await Messages
.OfType<EmailVerified>()
.TakeUntilTimeout($"Timeout_{i}", expiresIn: TimeSpan.FromDays(1))
.SuspendUntilFirstOrNone();
.FirstOrNone();

if (emailVerifiedOption.HasValue)
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

namespace Cleipnir.Flows.Sample.Presentation.F_SmsVerificationFlow;

public class SmsFlow : Flow<string>, IHaveState<SmsFlow.FlowState>
public class SmsFlow : Flow<string>, IHaveState<SmsFlow.SmsState>
{
public required FlowState State { get; init; }
public required SmsState State { get; init; }

public override async Task Run(string customerPhoneNumber)
{
Expand All @@ -24,7 +24,7 @@ public override async Task Run(string customerPhoneNumber)
var codeFromUser = await Messages
.OfType<CodeFromUser>()
.Skip(i)
.SuspendUntilFirst();
.First();

if (IsExpired(codeFromUser))
State.Status = MostRecentAttempt.CodeExpired;
Expand All @@ -40,7 +40,7 @@ public override async Task Run(string customerPhoneNumber)
State.Status = MostRecentAttempt.MaxAttemptsExceeded;
}

public class FlowState : WorkflowState
public class SmsState : FlowState
{
public MostRecentAttempt Status { get; set; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ await Effect.Capture(
.OfTypes<SupportTicketTaken, SupportTicketRejected>()
.Where(e => e.Match(taken => taken.Iteration, rejected => rejected.Iteration) == i)
.TakeUntilTimeout(timeoutEventId: i.ToString(), expiresIn: TimeSpan.FromMinutes(15))
.SuspendUntilFirstOrNone();
.FirstOrNone();

if (!option.HasValue && option.Value.AsObject() is SupportTicketTaken)
return; //ticket was taken in iteration i
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public override async Task Run(LoanApplication loanApplication)
.OfType<CreditCheckOutcome>()
.Take(3)
.TakeUntilTimeout("Timeout", TimeSpan.FromMinutes(15))
.SuspendUntilCompletion();
.Completion();

if (outcomes.Count < 2)
await MessageBroker.Send(LoanApplicationRejected(loanApplication));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public override async Task Run(string customerEmail)
var emailVerifiedOption = await Messages
.OfType<EmailVerified>()
.TakeUntilTimeout($"Timeout_{i}", expiresIn: TimeSpan.FromDays(1))
.SuspendUntilFirstOrNone();
.FirstOrNone();

if (emailVerifiedOption.HasValue)
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ await Effect.Capture(
)
)
.TakeUntilTimeout($"Timeout_{i}", expiresIn: TimeSpan.FromHours(1))
.SuspendUntilFirstOrDefault();
.FirstOrDefault();

if (either?.AsObject() is EngagementAccepted)
{
Expand Down
6 changes: 3 additions & 3 deletions Samples/Cleipnir.Flows.Samples.Console/State/StateFlow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace Cleipnir.Flows.Sample.ConsoleApp.State;

public class StateFlow : Flow<string, string>, IHaveState<StateFlow.FlowState>
public class StateFlow : Flow<string, string>, IHaveState<StateFlow.WorkflowState>
{
public required FlowState State { get; init; }
public required WorkflowState State { get; init; }

public override async Task<string> Run(string param)
{
Expand All @@ -19,7 +19,7 @@ public override async Task<string> Run(string param)
return param;
}

public class FlowState : WorkflowState
public class WorkflowState : FlowState
{
public DateTime? Started { get; set; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ private class RebusTestFlow : Flow, ISubscribeTo<MyMessage>

public override async Task Run()
{
ReceivedMyMessage = await Messages.FirstOfType<MyMessage>();
ReceivedMyMessage = await Messages.FirstOfType<MyMessage>(maxWait: TimeSpan.MaxValue);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public override Task Run()
return Task.CompletedTask;
}

public class FunFlowState : WorkflowState
public class FunFlowState : FlowState
{
public string Value { get; set; } = "";
}
Expand Down

0 comments on commit f7a298d

Please sign in to comment.