Browse Source
Better cancellation for migration. (#418)
* Better cancellation for migration.
pull/421/head
Sebastian Stehle
6 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with
7 additions and
5 deletions
-
src/Squidex.Infrastructure/Migrations/Migrator.cs
-
src/Squidex.Infrastructure/Orleans/GrainBootstrap.cs
-
src/Squidex/Config/Startup/MigratorHost.cs
-
tests/Squidex.Infrastructure.Tests/Migrations/MigratorTests.cs
|
|
|
@ -7,6 +7,7 @@ |
|
|
|
|
|
|
|
using System; |
|
|
|
using System.Linq; |
|
|
|
using System.Threading; |
|
|
|
using System.Threading.Tasks; |
|
|
|
using Squidex.Infrastructure.Log; |
|
|
|
|
|
|
|
@ -32,7 +33,7 @@ namespace Squidex.Infrastructure.Migrations |
|
|
|
this.log = log; |
|
|
|
} |
|
|
|
|
|
|
|
public async Task MigrateAsync() |
|
|
|
public async Task MigrateAsync(CancellationToken ct = default) |
|
|
|
{ |
|
|
|
var version = 0; |
|
|
|
|
|
|
|
@ -49,7 +50,7 @@ namespace Squidex.Infrastructure.Migrations |
|
|
|
|
|
|
|
version = await migrationStatus.GetVersionAsync(); |
|
|
|
|
|
|
|
while (true) |
|
|
|
while (!ct.IsCancellationRequested) |
|
|
|
{ |
|
|
|
var (newVersion, migrations) = migrationPath.GetNext(version); |
|
|
|
|
|
|
|
|
|
|
|
@ -28,6 +28,7 @@ namespace Squidex.Infrastructure.Orleans |
|
|
|
{ |
|
|
|
for (var i = 1; i <= NumTries; i++) |
|
|
|
{ |
|
|
|
ct.ThrowIfCancellationRequested(); |
|
|
|
try |
|
|
|
{ |
|
|
|
var grain = grainFactory.GetGrain<T>(SingleGrain.Id); |
|
|
|
|
|
|
|
@ -25,7 +25,7 @@ namespace Squidex.Config.Startup |
|
|
|
|
|
|
|
protected override Task StartAsync(ISemanticLog log, CancellationToken ct) |
|
|
|
{ |
|
|
|
return migrator.MigrateAsync(); |
|
|
|
return migrator.MigrateAsync(ct); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -108,7 +108,7 @@ namespace Squidex.Infrastructure.Migrations |
|
|
|
|
|
|
|
A.CallTo(() => migrator_1_2.UpdateAsync()).Throws(new ArgumentException()); |
|
|
|
|
|
|
|
await Assert.ThrowsAsync<MigrationFailedException>(sut.MigrateAsync); |
|
|
|
await Assert.ThrowsAsync<MigrationFailedException>(() => sut.MigrateAsync()); |
|
|
|
|
|
|
|
A.CallTo(() => migrator_0_1.UpdateAsync()).MustHaveHappened(); |
|
|
|
A.CallTo(() => migrator_1_2.UpdateAsync()).MustHaveHappened(); |
|
|
|
@ -147,7 +147,7 @@ namespace Squidex.Infrastructure.Migrations |
|
|
|
|
|
|
|
var sut = new Migrator(new InMemoryStatus(), path, log) { LockWaitMs = 2 }; |
|
|
|
|
|
|
|
await Task.WhenAll(Enumerable.Repeat(0, 10).Select(x => Task.Run(sut.MigrateAsync))); |
|
|
|
await Task.WhenAll(Enumerable.Repeat(0, 10).Select(x => Task.Run(() => sut.MigrateAsync()))); |
|
|
|
|
|
|
|
A.CallTo(() => migrator_0_1.UpdateAsync()) |
|
|
|
.MustHaveHappened(1, Times.Exactly); |
|
|
|
|