From 00e2bf8e1b5f7047976d7c8fd38327a43f798333 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Chalet?= Date: Wed, 30 Sep 2020 03:48:01 +0200 Subject: [PATCH] Execute the OpenIddict Quartz job 2 minutes after the application starts --- samples/Mvc.Server/Worker.cs | 2 +- src/OpenIddict.MongoDb/OpenIddictMongoDbHelpers.cs | 2 +- .../Stores/OpenIddictMongoDbApplicationStore.cs | 2 +- .../Stores/OpenIddictMongoDbAuthorizationStore.cs | 4 ++-- .../Stores/OpenIddictMongoDbScopeStore.cs | 2 +- .../Stores/OpenIddictMongoDbTokenStore.cs | 4 ++-- src/OpenIddict.Quartz/OpenIddictQuartzExtensions.cs | 8 ++++---- 7 files changed, 12 insertions(+), 12 deletions(-) diff --git a/samples/Mvc.Server/Worker.cs b/samples/Mvc.Server/Worker.cs index ed7d7739..d5c10074 100644 --- a/samples/Mvc.Server/Worker.cs +++ b/samples/Mvc.Server/Worker.cs @@ -21,7 +21,7 @@ namespace Mvc.Server using var scope = _serviceProvider.CreateScope(); var context = scope.ServiceProvider.GetRequiredService(); - await context.Database.EnsureCreatedAsync(); + await context.Database.EnsureCreatedAsync(cancellationToken); await RegisterApplicationsAsync(scope.ServiceProvider); await RegisterScopesAsync(scope.ServiceProvider); diff --git a/src/OpenIddict.MongoDb/OpenIddictMongoDbHelpers.cs b/src/OpenIddict.MongoDb/OpenIddictMongoDbHelpers.cs index 108c3652..eff3ff29 100644 --- a/src/OpenIddict.MongoDb/OpenIddictMongoDbHelpers.cs +++ b/src/OpenIddict.MongoDb/OpenIddictMongoDbHelpers.cs @@ -35,7 +35,7 @@ namespace MongoDB.Driver static async IAsyncEnumerable ExecuteAsync(IAsyncCursorSource source, [EnumeratorCancellation] CancellationToken cancellationToken) { - using var cursor = await source.ToCursorAsync(); + using var cursor = await source.ToCursorAsync(cancellationToken); while (await cursor.MoveNextAsync(cancellationToken)) { diff --git a/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbApplicationStore.cs b/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbApplicationStore.cs index 60780695..58142cc8 100644 --- a/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbApplicationStore.cs +++ b/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbApplicationStore.cs @@ -102,7 +102,7 @@ namespace OpenIddict.MongoDb if ((await collection.DeleteOneAsync(entity => entity.Id == application.Id && - entity.ConcurrencyToken == application.ConcurrencyToken)).DeletedCount == 0) + entity.ConcurrencyToken == application.ConcurrencyToken, cancellationToken)).DeletedCount == 0) { throw new OpenIddictExceptions.ConcurrencyException(SR.GetResourceString(SR.ID0239)); } diff --git a/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbAuthorizationStore.cs b/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbAuthorizationStore.cs index 145d14c8..a7911c46 100644 --- a/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbAuthorizationStore.cs +++ b/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbAuthorizationStore.cs @@ -102,7 +102,7 @@ namespace OpenIddict.MongoDb if ((await collection.DeleteOneAsync(entity => entity.Id == authorization.Id && - entity.ConcurrencyToken == authorization.ConcurrencyToken)).DeletedCount == 0) + entity.ConcurrencyToken == authorization.ConcurrencyToken, cancellationToken)).DeletedCount == 0) { throw new OpenIddictExceptions.ConcurrencyException(SR.GetResourceString(SR.ID0241)); } @@ -546,7 +546,7 @@ namespace OpenIddict.MongoDb // maximum number of elements that can be removed by a single call to PruneAsync() is limited to 50000. foreach (var buffer in Buffer(identifiers.Take(50_000), 1_000)) { - await collection.DeleteManyAsync(authorization => buffer.Contains(authorization.Id)); + await collection.DeleteManyAsync(authorization => buffer.Contains(authorization.Id), cancellationToken); } static IEnumerable> Buffer(IEnumerable source, int count) diff --git a/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbScopeStore.cs b/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbScopeStore.cs index d1de7a8c..e88a9212 100644 --- a/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbScopeStore.cs +++ b/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbScopeStore.cs @@ -102,7 +102,7 @@ namespace OpenIddict.MongoDb if ((await collection.DeleteOneAsync(entity => entity.Id == scope.Id && - entity.ConcurrencyToken == scope.ConcurrencyToken)).DeletedCount == 0) + entity.ConcurrencyToken == scope.ConcurrencyToken, cancellationToken)).DeletedCount == 0) { throw new OpenIddictExceptions.ConcurrencyException(SR.GetResourceString(SR.ID0245)); } diff --git a/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbTokenStore.cs b/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbTokenStore.cs index fc3883cd..3089dcc2 100644 --- a/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbTokenStore.cs +++ b/src/OpenIddict.MongoDb/Stores/OpenIddictMongoDbTokenStore.cs @@ -102,7 +102,7 @@ namespace OpenIddict.MongoDb if ((await collection.DeleteOneAsync(entity => entity.Id == token.Id && - entity.ConcurrencyToken == token.ConcurrencyToken)).DeletedCount == 0) + entity.ConcurrencyToken == token.ConcurrencyToken, cancellationToken)).DeletedCount == 0) { throw new OpenIddictExceptions.ConcurrencyException(SR.GetResourceString(SR.ID0247)); } @@ -562,7 +562,7 @@ namespace OpenIddict.MongoDb // maximum number of elements that can be removed by a single call to PruneAsync() is limited to 50000. foreach (var buffer in Buffer(identifiers.Take(50_000), 1_000)) { - await collection.DeleteManyAsync(token => buffer.Contains(token.Id)); + await collection.DeleteManyAsync(token => buffer.Contains(token.Id), cancellationToken); } static IEnumerable> Buffer(IEnumerable source, int count) diff --git a/src/OpenIddict.Quartz/OpenIddictQuartzExtensions.cs b/src/OpenIddict.Quartz/OpenIddictQuartzExtensions.cs index e0756c71..8883ed56 100644 --- a/src/OpenIddict.Quartz/OpenIddictQuartzExtensions.cs +++ b/src/OpenIddict.Quartz/OpenIddictQuartzExtensions.cs @@ -58,15 +58,15 @@ namespace Microsoft.Extensions.DependencyInjection descriptor.ImplementationInstance is ITrigger trigger && trigger.JobKey.Equals(OpenIddictQuartzJob.Identity))) { - // Note: this trigger uses a quite long interval (1 hour), which means it may be - // potentially never reached if the application is shut down or recycled. As such, - // this trigger is set up to fire immediately to ensure it's executed at least once. + // Note: this trigger uses a quite long interval (1 hour), which means it may be potentially + // never reached if the application is shut down or recycled. As such, this trigger is set up + // to fire 2 minutes after the application starts to ensure it's executed at least once. builder.Services.AddSingleton( TriggerBuilder.Create() .ForJob(OpenIddictQuartzJob.Identity) .WithSimpleSchedule(options => options.WithIntervalInHours(1).RepeatForever()) .WithDescription(SR.GetResourceString(SR.ID8001)) - .StartNow() + .StartAt(DateBuilder.FutureDate(2, IntervalUnit.Minute)) .Build()); }