Skip to content

Commit

Permalink
Fix in backup.
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastianStehle committed Mar 23, 2022
1 parent 0ebcf32 commit 8e44562
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 4 deletions.
3 changes: 2 additions & 1 deletion backend/src/Squidex.Domain.Apps.Entities/Apps/BackupApps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,11 @@ public async Task CleanupRestoreErrorAsync(DomainId appId)
await appsIndex.RemoveReservationAsync(appReservation);
}

public async Task CompleteRestoreAsync(RestoreContext context)
public async Task CompleteRestoreAsync(RestoreContext context, string appName)
{
await rebuilder.InsertManyAsync<AppDomainObject, AppDomainObject.State>(Enumerable.Repeat(context.AppId, 1), 1, default);

await appsIndex.RegisterAsync(context.AppId, appName);
await appsIndex.RemoveReservationAsync(appReservation);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ public AppsIndex(IAppRepository appRepository, IGrainFactory grainFactory, IRepl
this.grainCache = grainCache;
}

public Task RegisterAsync(DomainId id, string name,
CancellationToken ct = default)
{
return Cache().AddAsync(id, name);
}

public Task RemoveReservationAsync(string? token,
CancellationToken ct = default)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ Task<List<IAppEntity>> GetAppsForUserAsync(string userId, PermissionSet permissi
Task<string?> ReserveAsync(DomainId id, string name,
CancellationToken ct = default);

Task RegisterAsync(DomainId id, string name,
CancellationToken ct = default);

Task RemoveReservationAsync(string? token,
CancellationToken ct = default);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public Task CleanupRestoreErrorAsync(DomainId appId)
return Task.CompletedTask;
}

public Task CompleteRestoreAsync(RestoreContext context)
public Task CompleteRestoreAsync(RestoreContext context, string appName)
{
return Task.CompletedTask;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ private async Task ProcessAsync()
{
using (Telemetry.Activities.StartActivity($"{handler.GetType().Name}/CompleteRestoreAsync"))
{
await handler.CompleteRestoreAsync(runningContext);
await handler.CompleteRestoreAsync(runningContext, CurrentJob.NewAppName!);
}

Log($"Completed {handler.Name}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,14 @@ await sut.RestoreEventAsync(Envelope.Create(new AppCreated
Name = appName
}), context, ct);

await sut.CompleteRestoreAsync(context);
await sut.CompleteRestoreAsync(context, appName);

A.CallTo(() => appsIndex.RemoveReservationAsync("Reservation", default))
.MustHaveHappened();

A.CallTo(() => appsIndex.RegisterAsync(appId, appName, default))
.MustHaveHappened();

A.CallTo(() => rebuilder.InsertManyAsync<AppDomainObject, AppDomainObject.State>(A<IEnumerable<DomainId>>.That.Is(appId), 1, default))
.MustHaveHappened();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,15 @@ public async Task Should_forward_remove_reservation()
.MustHaveHappened();
}

[Fact]
public async Task Should_forward_registation()
{
await sut.RegisterAsync(appId.Id, appId.Name);

A.CallTo(() => cache.AddAsync(appId.Id, appId.Name))
.MustHaveHappened();
}

private (IAppEntity, IAppGrain) CreateApp(long version = 0, bool fromClient = false, bool isArchived = false)
{
var app = A.Fake<IAppEntity>();
Expand Down

0 comments on commit 8e44562

Please sign in to comment.