diff --git a/backend/src/Squidex.Domain.Apps.Entities/Billing/UsageNotifierWorker.cs b/backend/src/Squidex.Domain.Apps.Entities/Billing/UsageNotifierWorker.cs index 431a8e0fe..2cdbb98bf 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Billing/UsageNotifierWorker.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Billing/UsageNotifierWorker.cs @@ -7,6 +7,7 @@ using NodaTime; using Squidex.Domain.Apps.Entities.Notifications; +using Squidex.Hosting; using Squidex.Infrastructure; using Squidex.Infrastructure.States; using Squidex.Messaging; @@ -14,7 +15,7 @@ using Squidex.Shared.Users; namespace Squidex.Domain.Apps.Entities.Billing { - public sealed class UsageNotifierWorker : IMessageHandler + public sealed class UsageNotifierWorker : IMessageHandler, IInitializable { private static readonly TimeSpan TimeBetweenNotifications = TimeSpan.FromDays(3); private readonly SimpleState state; @@ -42,6 +43,12 @@ namespace Squidex.Domain.Apps.Entities.Billing state = new SimpleState(persistenceFactory, GetType(), DomainId.Create("Default")); } + public Task InitializeAsync( + CancellationToken ct) + { + return state.LoadAsync(ct); + } + public async Task HandleAsync(UsageTrackingCheck notification, CancellationToken ct) { diff --git a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Billing/UsageNotifierWorkerTest.cs b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Billing/UsageNotifierWorkerTest.cs index 5609ed3e1..9a6f9ab29 100644 --- a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Billing/UsageNotifierWorkerTest.cs +++ b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Billing/UsageNotifierWorkerTest.cs @@ -46,6 +46,15 @@ namespace Squidex.Domain.Apps.Entities.Billing }; } + [Fact] + public async Task Should_load_on_initialize() + { + await sut.InitializeAsync(default); + + A.CallTo(() => state.Persistence.ReadAsync(EtagVersion.Any, default)) + .MustHaveHappened(); + } + [Fact] public async Task Should_not_send_notification_if_not_active() {