mirror of https://github.com/Squidex/squidex.git
12 changed files with 222 additions and 60 deletions
@ -0,0 +1,44 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using Orleans; |
|||
using Squidex.Domain.Apps.Entities.Apps.Commands; |
|||
using Squidex.Infrastructure; |
|||
using Squidex.Infrastructure.Commands; |
|||
using Squidex.Infrastructure.Orleans; |
|||
|
|||
namespace Squidex.Domain.Apps.Entities.Backup |
|||
{ |
|||
public sealed class EnqueueAppToCleanerMiddleware : ICommandMiddleware |
|||
{ |
|||
private readonly ICleanerGrain cleaner; |
|||
|
|||
public EnqueueAppToCleanerMiddleware(IGrainFactory grainFactory) |
|||
{ |
|||
Guard.NotNull(grainFactory, nameof(grainFactory)); |
|||
|
|||
cleaner = grainFactory.GetGrain<ICleanerGrain>(SingleGrain.Id); |
|||
} |
|||
|
|||
public async Task HandleAsync(CommandContext context, Func<Task> next) |
|||
{ |
|||
if (context.IsCompleted) |
|||
{ |
|||
switch (context.Command) |
|||
{ |
|||
case ArchiveApp archiveApp: |
|||
await cleaner.EnqueueAppAsync(archiveApp.AppId); |
|||
break; |
|||
} |
|||
} |
|||
|
|||
await next(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,18 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using Squidex.Infrastructure.Orleans; |
|||
|
|||
namespace Squidex.Domain.Apps.Entities.Backup |
|||
{ |
|||
public interface ICleanerGrain : IBackgroundGrain |
|||
{ |
|||
Task EnqueueAppAsync(Guid appId); |
|||
} |
|||
} |
|||
@ -0,0 +1,48 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using FakeItEasy; |
|||
using Orleans; |
|||
using Squidex.Domain.Apps.Entities.Apps.Commands; |
|||
using Squidex.Infrastructure.Commands; |
|||
using Squidex.Infrastructure.Orleans; |
|||
using Xunit; |
|||
|
|||
namespace Squidex.Domain.Apps.Entities.Backup |
|||
{ |
|||
public class EnqueueAppToCleanerMiddlewareTests |
|||
{ |
|||
private readonly IGrainFactory grainFactory = A.Fake<IGrainFactory>(); |
|||
private readonly ICommandBus commandBus = A.Fake<ICommandBus>(); |
|||
private readonly ICleanerGrain index = A.Fake<ICleanerGrain>(); |
|||
private readonly Guid appId = Guid.NewGuid(); |
|||
private readonly EnqueueAppToCleanerMiddleware sut; |
|||
|
|||
public EnqueueAppToCleanerMiddlewareTests() |
|||
{ |
|||
A.CallTo(() => grainFactory.GetGrain<ICleanerGrain>(SingleGrain.Id, null)) |
|||
.Returns(index); |
|||
|
|||
sut = new EnqueueAppToCleanerMiddleware(grainFactory); |
|||
} |
|||
|
|||
[Fact] |
|||
public async Task Should_enqueue_for_cleanup_on_archive() |
|||
{ |
|||
var context = |
|||
new CommandContext(new ArchiveApp { AppId = appId }, commandBus) |
|||
.Complete(); |
|||
|
|||
await sut.HandleAsync(context); |
|||
|
|||
A.CallTo(() => index.EnqueueAppAsync(appId)) |
|||
.MustHaveHappened(); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue