Skip to content

Commit

Permalink
Rename TimeoutProvider to Timeouts
Browse files Browse the repository at this point in the history
  • Loading branch information
stidsborg committed Aug 4, 2024
1 parent 026221e commit c7624ea
Show file tree
Hide file tree
Showing 21 changed files with 53 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ await functionStore.CreateFunction(
);
var eventSerializer = new EventSerializer();
var messagesWriter = new MessageWriter(functionId, functionStore, eventSerializer, scheduleReInvocation: (_, _) => Task.CompletedTask);
var timeoutProvider = new TimeoutProvider(functionId, functionStore.TimeoutStore);
var timeoutProvider = new Timeouts(functionId, functionStore.TimeoutStore);
var messagesPullerAndEmitter = new MessagesPullerAndEmitter(
functionId,
defaultDelay: TimeSpan.FromSeconds(1),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ await functionStore.CreateFunction(
timestamp: DateTime.UtcNow.Ticks
);
var messagesWriter = new MessageWriter(functionId, functionStore, DefaultSerializer.Instance, scheduleReInvocation: (_, _) => Task.CompletedTask);
var timeoutProvider = new TimeoutProvider(functionId, functionStore.TimeoutStore);
var timeoutProvider = new Timeouts(functionId, functionStore.TimeoutStore);
var messagesPullerAndEmitter = new MessagesPullerAndEmitter(
functionId,
defaultDelay: TimeSpan.FromMilliseconds(250),
Expand Down Expand Up @@ -64,7 +64,7 @@ await functionStore.CreateFunction(
timestamp: DateTime.UtcNow.Ticks
);
var messagesWriter = new MessageWriter(functionId, functionStore, DefaultSerializer.Instance, scheduleReInvocation: (_, _) => Task.CompletedTask);
var timeoutProvider = new TimeoutProvider(functionId, functionStore.TimeoutStore);
var timeoutProvider = new Timeouts(functionId, functionStore.TimeoutStore);
var messagesPullerAndEmitter = new MessagesPullerAndEmitter(
functionId,
defaultDelay: TimeSpan.FromMilliseconds(250),
Expand Down Expand Up @@ -102,7 +102,7 @@ await functionStore.CreateFunction(
timestamp: DateTime.UtcNow.Ticks
);
var messagesWriter = new MessageWriter(functionId, functionStore, DefaultSerializer.Instance, scheduleReInvocation: (_, _) => Task.CompletedTask);
var timeoutProvider = new TimeoutProvider(functionId, functionStore.TimeoutStore);
var timeoutProvider = new Timeouts(functionId, functionStore.TimeoutStore);
var messagesPullerAndEmitter = new MessagesPullerAndEmitter(
functionId,
defaultDelay: TimeSpan.FromMilliseconds(250),
Expand Down Expand Up @@ -145,7 +145,7 @@ await functionStore.CreateFunction(
timestamp: DateTime.UtcNow.Ticks
);
var messagesWriter = new MessageWriter(functionId, functionStore, DefaultSerializer.Instance, scheduleReInvocation: (_, _) => Task.CompletedTask);
var timeoutProvider = new TimeoutProvider(functionId, functionStore.TimeoutStore);
var timeoutProvider = new Timeouts(functionId, functionStore.TimeoutStore);
var messagesPullerAndEmitter = new MessagesPullerAndEmitter(
functionId,
defaultDelay: TimeSpan.FromMilliseconds(250),
Expand Down Expand Up @@ -187,7 +187,7 @@ await functionStore.CreateFunction(
timestamp: DateTime.UtcNow.Ticks
);
var messagesWriter = new MessageWriter(functionId, functionStore, DefaultSerializer.Instance, scheduleReInvocation: (_, _) => Task.CompletedTask);
var timeoutProvider = new TimeoutProvider(functionId, functionStore.TimeoutStore);
var timeoutProvider = new Timeouts(functionId, functionStore.TimeoutStore);
var messagesPullerAndEmitter = new MessagesPullerAndEmitter(
functionId,
defaultDelay: TimeSpan.FromMilliseconds(250),
Expand Down Expand Up @@ -225,7 +225,7 @@ await functionStore.CreateFunction(
timestamp: DateTime.UtcNow.Ticks
);
var messagesWriter = new MessageWriter(functionId, functionStore, DefaultSerializer.Instance, scheduleReInvocation: (_, _) => Task.CompletedTask);
var timeoutProvider = new TimeoutProvider(functionId, functionStore.TimeoutStore);
var timeoutProvider = new Timeouts(functionId, functionStore.TimeoutStore);
var messagesPullerAndEmitter = new MessagesPullerAndEmitter(
functionId,
defaultDelay: TimeSpan.FromMilliseconds(250),
Expand Down Expand Up @@ -275,7 +275,7 @@ await functionStore.CreateFunction(
timestamp: DateTime.UtcNow.Ticks
);
var messagesWriter = new MessageWriter(functionId, functionStore, DefaultSerializer.Instance, scheduleReInvocation: (_, _) => Task.CompletedTask);
var timeoutProvider = new TimeoutProvider(functionId, functionStore.TimeoutStore);
var timeoutProvider = new Timeouts(functionId, functionStore.TimeoutStore);
var messagesPullerAndEmitter = new MessagesPullerAndEmitter(
functionId,
defaultDelay: TimeSpan.FromMilliseconds(250),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

namespace Cleipnir.ResilientFunctions.Tests.ReactiveTests;

public class NoOpTimeoutProvider : ITimeoutProvider
public class NoOpTimeouts : ITimeouts
{
public static NoOpTimeoutProvider Instance { get; } = new();
public static NoOpTimeouts Instance { get; } = new();
public Task RegisterTimeout(string timeoutId, DateTime expiresAt)
=> Task.CompletedTask;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public async Task SyncingStopsAfterReactiveChainCompletion()
var counter = new SyncedCounter();

var source = new TestSource(
NoOpTimeoutProvider.Instance,
NoOpTimeouts.Instance,
syncStore: _ =>
{
counter.Increment();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ namespace Cleipnir.ResilientFunctions.Tests.ReactiveTests;

public class TestSource : Source
{
public TestSource(ITimeoutProvider? timeoutProvider = null, SyncStore? syncStore = null) : base(
timeoutProvider ?? NoOpTimeoutProvider.Instance,
public TestSource(ITimeouts? timeoutProvider = null, SyncStore? syncStore = null) : base(
timeoutProvider ?? NoOpTimeouts.Instance,
syncStore: syncStore ?? (_ => new InterruptCount(0).ToTask()),
defaultDelay: TimeSpan.FromMilliseconds(10),
defaultMaxWait: TimeSpan.MaxValue,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public async Task StreamCompletesAndThrowsNoResultExceptionAfterFiredTimeoutEven
var timeoutId = "TimeoutId";
var expiresAt = DateTime.UtcNow.Add(TimeSpan.FromMinutes(15));

var timeoutProviderStub = new TimeoutProviderStub();
var timeoutProviderStub = new TimeoutsStub();
var source = new TestSource(timeoutProviderStub);

var task = source.TakeUntilTimeout(timeoutId, expiresAt).First();
Expand All @@ -47,7 +47,7 @@ public async Task StreamCompletesAndReturnsNothingAfterFiredTimeoutEvent()
var timeoutId = "TimeoutId";
var expiresAt = DateTime.UtcNow.Add(TimeSpan.FromMinutes(15));

var timeoutProviderStub = new TimeoutProviderStub();
var timeoutProviderStub = new TimeoutsStub();
var source = new TestSource(timeoutProviderStub);

var task = source.TakeUntilTimeout(timeoutId, expiresAt).FirstOrNone();
Expand All @@ -73,7 +73,7 @@ public async Task StreamCompletesSuccessfullyWhenEventSupersedesTimeout()
var timeoutId = "TimeoutId";
var expiresAt = DateTime.UtcNow.Add(TimeSpan.FromMinutes(15));

var timeoutProviderStub = new TimeoutProviderStub();
var timeoutProviderStub = new TimeoutsStub();
var source = new TestSource(timeoutProviderStub);

var task = source.TakeUntilTimeout(timeoutId, expiresAt).First();
Expand All @@ -91,7 +91,7 @@ public async Task StreamCompletesSuccessfullyWithValuedOptionWhenEventSupersedes
var timeoutId = "TimeoutId";
var expiresAt = DateTime.UtcNow.Add(TimeSpan.FromMinutes(15));

var timeoutProviderStub = new TimeoutProviderStub();
var timeoutProviderStub = new TimeoutsStub();
var source = new TestSource(timeoutProviderStub);

var task = source.TakeUntilTimeout(timeoutId, expiresAt).FirstOrNone();
Expand All @@ -105,7 +105,7 @@ public async Task StreamCompletesSuccessfullyWithValuedOptionWhenEventSupersedes
option.Value.ShouldBe("Hello");
}

private class TimeoutProviderStub : ITimeoutProvider
private class TimeoutsStub : ITimeouts
{
public List<Tuple<string, DateTime>> Registrations
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ protected async Task ExistingActionCanBeDeletedFromControlPanel(Task<IFunctionSt
await messages.AppendMessage("Message");
var state = states.CreateOrGet<State>();
state.Value = "State";
await workflow.Messages.TimeoutProvider.RegisterTimeout("Timeout", TimeSpan.FromDays(1));
await workflow.Messages.Timeouts.RegisterTimeout("Timeout", TimeSpan.FromDays(1));
await state.Save();
}
);
Expand Down Expand Up @@ -96,7 +96,7 @@ async Task<string>(string _, Workflow workflow) =>
var state = states.CreateOrGet<State>();
state.Value = "State";
await state.Save();
await workflow.Messages.TimeoutProvider.RegisterTimeout("Timeout", TimeSpan.FromDays(1));
await workflow.Messages.Timeouts.RegisterTimeout("Timeout", TimeSpan.FromDays(1));
return "hello";
});

Expand Down Expand Up @@ -1478,7 +1478,7 @@ protected async Task ExistingTimeoutCanBeUpdatedForAction(Task<IFunctionStore> s
var actionRegistration = functionsRegistry.RegisterAction(
flowType,
Task (string param, Workflow workflow) =>
workflow.Messages.TimeoutProvider.RegisterTimeout(
workflow.Messages.Timeouts.RegisterTimeout(
"someTimeoutId", expiresAt: new DateTime(2100, 1,1, 1,1,1, DateTimeKind.Utc)
)
);
Expand Down Expand Up @@ -1518,7 +1518,7 @@ protected async Task ExistingTimeoutCanBeUpdatedForFunc(Task<IFunctionStore> sto
flowType,
async Task<string> (string param, Workflow workflow) =>
{
await workflow.Messages.TimeoutProvider.RegisterTimeout(
await workflow.Messages.Timeouts.RegisterTimeout(
"someTimeoutId", expiresAt: new DateTime(2100, 1, 1, 1, 1, 1, DateTimeKind.Utc)
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ protected async Task ExpiredTimeoutIsAddedToMessages(Task<IFunctionStore> storeT
{
var messages = workflow.Messages;
var timeoutTask = messages.OfType<TimeoutEvent>().First();
await messages.TimeoutProvider.RegisterTimeout("test", expiresIn: TimeSpan.FromMilliseconds(500));
await messages.Timeouts.RegisterTimeout("test", expiresIn: TimeSpan.FromMilliseconds(500));
timeoutTask.IsCompleted.ShouldBeFalse();
var timeout = await timeoutTask;
timeout.TimeoutId.ShouldBe("test");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ protected async Task RegisteredTimeoutIsReturnedFromTimeoutProvider(Task<ITimeou
var store = await storeTask;
var functionId = TestFlowId.Create();

var timeoutProvider = new TimeoutProvider(functionId, store);
var timeoutProvider = new Timeouts(functionId, store);

await timeoutProvider.RegisterTimeout("timeoutId1", expiresIn: TimeSpan.FromHours(1));
await timeoutProvider.RegisterTimeout("timeoutId2", expiresIn: TimeSpan.FromHours(2));
Expand All @@ -126,9 +126,9 @@ protected async Task RegisteredTimeoutIsReturnedFromTimeoutProviderForFunctionId
var store = await storeTask;
var functionId = TestFlowId.Create();

var timeoutProvider = new TimeoutProvider(functionId, store);
var timeoutProvider = new Timeouts(functionId, store);

var otherInstanceTimeoutProvider = new TimeoutProvider(
var otherInstanceTimeoutProvider = new Timeouts(
new FlowId(functionId.Type, functionId.Instance.Value + "2"),
store
);
Expand All @@ -152,7 +152,7 @@ protected async Task TimeoutIsNotRegisteredAgainWhenProviderAlreadyContainsTimeo
var store = new TimeoutStoreDecorator(await storeTask, () => upsertCount++);
var functionId = TestFlowId.Create();

var timeoutProvider = new TimeoutProvider(functionId, store);
var timeoutProvider = new Timeouts(functionId, store);

await timeoutProvider.RegisterTimeout("timeoutId1", expiresIn: TimeSpan.FromHours(1));
upsertCount.ShouldBe(1);
Expand All @@ -172,7 +172,7 @@ protected async Task CancellingNonExistingTimeoutDoesNotResultInIO(Task<ITimeout
var store = new TimeoutStoreDecorator(await storeTask, removeTimeoutCallback: () => removeCount++);
var functionId = TestFlowId.Create();

var timeoutProvider = new TimeoutProvider(functionId, store);
var timeoutProvider = new Timeouts(functionId, store);

var pendingTimeouts = await timeoutProvider.PendingTimeouts();
pendingTimeouts.ShouldBeEmpty();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ await _functionStore.BulkScheduleFunctions(
public Messages CreateMessages(FlowId flowId, ScheduleReInvocation scheduleReInvocation, Func<bool> isWorkflowRunning)
{
var messageWriter = new MessageWriter(flowId, _functionStore, Serializer, scheduleReInvocation);
var timeoutProvider = new TimeoutProvider(flowId, _functionStore.TimeoutStore);
var timeoutProvider = new Timeouts(flowId, _functionStore.TimeoutStore);
var messagesPullerAndEmitter = new MessagesPullerAndEmitter(
flowId,
defaultDelay: _settings.MessagesPullFrequency,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@

namespace Cleipnir.ResilientFunctions.CoreRuntime;

public interface ITimeoutProvider
public interface ITimeouts
{
Task RegisterTimeout(string timeoutId, DateTime expiresAt);
Task RegisterTimeout(string timeoutId, TimeSpan expiresIn);
Task CancelTimeout(string timeoutId);
Task<IReadOnlyList<TimeoutEvent>> PendingTimeouts();
}

public class TimeoutProvider : ITimeoutProvider
public class Timeouts : ITimeouts
{
private readonly ITimeoutStore _timeoutStore;

Expand All @@ -25,7 +25,7 @@ public class TimeoutProvider : ITimeoutProvider

private readonly FlowId _flowId;

public TimeoutProvider(FlowId flowId, ITimeoutStore timeoutStore)
public Timeouts(FlowId flowId, ITimeoutStore timeoutStore)
{
_timeoutStore = timeoutStore;
_flowId = flowId;
Expand Down
6 changes: 3 additions & 3 deletions Core/Cleipnir.ResilientFunctions/Messaging/Messages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@ namespace Cleipnir.ResilientFunctions.Messaging;

public class Messages : IReactiveChain<object>
{
public TimeoutProvider TimeoutProvider { get; }
public Timeouts Timeouts { get; }
public IReactiveChain<object> Source => _messagePullerAndEmitter.Source;

private readonly MessageWriter _messageWriter;
private readonly MessagesPullerAndEmitter _messagePullerAndEmitter;

public Messages(
MessageWriter messageWriter,
TimeoutProvider timeoutProvider,
Timeouts timeouts,
MessagesPullerAndEmitter messagePullerAndEmitter
)
{
_messageWriter = messageWriter;
TimeoutProvider = timeoutProvider;
Timeouts = timeouts;
_messagePullerAndEmitter = messagePullerAndEmitter;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public MessagesPullerAndEmitter(
TimeSpan defaultDelay,
TimeSpan defaultMaxWait,
Func<bool> isWorkflowRunning,
IFunctionStore functionStore, ISerializer serializer, ITimeoutProvider timeoutProvider)
IFunctionStore functionStore, ISerializer serializer, ITimeouts timeouts)
{
_flowId = flowId;
_functionStore = functionStore;
Expand All @@ -55,7 +55,7 @@ public MessagesPullerAndEmitter(
_serializer = serializer;

Source = new Source(
timeoutProvider,
timeouts,
syncStore: PullEvents,
defaultDelay,
defaultMaxWait,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public static async Task SuspendUntil(this Messages s, string timeoutEventId, Da
if (timeoutEmitted)
return;

await subscription.TimeoutProvider.RegisterTimeout(timeoutEventId, resumeAt);
await subscription.Timeouts.RegisterTimeout(timeoutEventId, resumeAt);
throw new SuspendInvocationException(interruptCount);
}

Expand Down
2 changes: 1 addition & 1 deletion Core/Cleipnir.ResilientFunctions/Reactive/ISubscription.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public interface ISubscription
{
bool IsWorkflowRunning { get; }
IReactiveChain<object> Source { get; }
ITimeoutProvider TimeoutProvider { get; }
ITimeouts Timeouts { get; }

TimeSpan DefaultMessageSyncDelay { get; }
TimeSpan DefaultMessageMaxWait { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public Subscription(

public bool IsWorkflowRunning => _subscription.IsWorkflowRunning;
public IReactiveChain<object> Source => _subscription.Source;
public ITimeoutProvider TimeoutProvider => _subscription.TimeoutProvider;
public ITimeouts Timeouts => _subscription.Timeouts;
public Task Initialize() => _subscription.Initialize();

public Task SyncStore(TimeSpan maxSinceLastSynced) => _subscription.SyncStore(maxSinceLastSynced);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public Subscription(
_innerSubscription = inner.Subscribe(OnNext, OnCompletion, OnError);
}

public ITimeoutProvider TimeoutProvider => _innerSubscription.TimeoutProvider;
public ITimeouts Timeouts => _innerSubscription.Timeouts;

public Task Initialize() => _innerSubscription.Initialize();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public async Task RegisterTimeoutIfNotInExistingEvents()

try
{
await _innerSubscription.TimeoutProvider.RegisterTimeout(_timeoutId, _expiresAt);
await _innerSubscription.Timeouts.RegisterTimeout(_timeoutId, _expiresAt);
}
catch (Exception exception)
{
Expand All @@ -87,7 +87,7 @@ public async Task RegisterTimeoutIfNotInExistingEvents()

public bool IsWorkflowRunning => _innerSubscription.IsWorkflowRunning;
public IReactiveChain<object> Source => _innerSubscription.Source;
public ITimeoutProvider TimeoutProvider => _innerSubscription.TimeoutProvider;
public ITimeouts Timeouts => _innerSubscription.Timeouts;

public async Task Initialize()
{
Expand Down
Loading

0 comments on commit c7624ea

Please sign in to comment.