Quartz Never Runs and Performs Cleanup of Tokens and Authorizations
See original GitHub issueConfirm you’ve already contributed to this project or that you sponsor it
- I confirm I’m a sponsor or a contributor
Version
3.x
Question
I am slightly confused here. I have followed the examples and looked at the configuration class in the source code. I am adding the Quartz support
public static IServiceCollection AddQuartzServices(this IServiceCollection services)
{
// Quartz here is used to automatically prune/remove authorization and token entries that
// are no longer valid from the database.
return services
.AddQuartz(options =>
{
options.UseMicrosoftDependencyInjectionJobFactory();
options.UseSimpleTypeLoader();
options.UseInMemoryStore();
})
// Register the Quartz.NET service and configure it to block shutdown until jobs are complete.
.AddQuartzHostedService(options => options.WaitForJobsToComplete = true);
}
I then add the Core service and initialize with UseQuartz
services
.AddOpenIddict()
.AddCore(options =>
{
options.UseMongoDb()
.UseDatabase(new MongoClient(_mongoDbSettings.ConnectionString).GetDatabase(_mongoDbSettings.DatabaseName))
.SetApplicationsCollectionName("applications")
.SetAuthorizationsCollectionName("authorizations")
.SetTokensCollectionName("tokens")
.SetScopesCollectionName("scopes");
options.UseQuartz(builder =>
{
builder.Configure(o => { o.MaximumRefireCount = 3; });
});
// I have also tried
// options.UseQuartz();
})
This gives the following output,
[12:39:12.720 INF] [] [Quartz.Core.SchedulerSignalerImpl] Initialized Scheduler Signaller of type: Quartz.Core.SchedulerSignalerImpl [12:39:12.721 INF] [] [Quartz.Core.QuartzScheduler] Quartz Scheduler created [12:39:12.721 INF] [] [Quartz.Core.QuartzScheduler] JobFactory set to: Quartz.Simpl.MicrosoftDependencyInjectionJobFactory [12:39:12.721 INF] [] [Quartz.Simpl.RAMJobStore] RAMJobStore initialized. [12:39:12.723 INF] [] [Quartz.Core.QuartzScheduler] Scheduler meta-data: Quartz Scheduler (v3.4.0.0) ‘QuartzScheduler’ with instanceId ‘NON_CLUSTERED’ Scheduler class: ‘Quartz.Core.QuartzScheduler’ - running locally. NOT STARTED. Currently in standby mode. Number of jobs executed: 0 Using thread pool ‘Quartz.Simpl.DefaultThreadPool’ - with 10 threads. Using job-store ‘Quartz.Simpl.RAMJobStore’ - which does not support persistence. and is not clustered.
[12:39:12.723 INF] [] [Quartz.Impl.StdSchedulerFactory] Quartz scheduler ‘QuartzScheduler’ initialized [12:39:12.723 INF] [] [Quartz.Impl.StdSchedulerFactory] Quartz scheduler version: 3.4.0.0 [12:39:12.738 INF] [] [Quartz.ContainerConfigurationProcessor] Adding 1 jobs, 1 triggers. [12:39:12.739 INF] [] [Quartz.ContainerConfigurationProcessor] Adding job: OpenIddict.Quartz.OpenIddictQuartzJob // … Other logging … [12:39:13.316 WRN] [] [Microsoft.AspNetCore.Server.Kestrel] Overriding address(es) ‘“https://localhost:6699”’. Binding to endpoints defined via IConfiguration and/or UseKestrel() instead. [12:39:13.337 INF] [] [Microsoft.Hosting.Lifetime] Now listening on: “https://[::]:6699” [12:39:13.337 INF] [] [Microsoft.Hosting.Lifetime] Application started. Press Ctrl+C to shut down. [12:39:13.337 INF] [] [Microsoft.Hosting.Lifetime] Hosting environment: “Localhost” [12:39:13.338 INF] [] [Microsoft.Hosting.Lifetime] Content root path: “C:\VRPM\Repos\authentication-server\src\Services\Migr8.AuthenticationServer\bin\Debug\net6.0” [12:39:13.343 INF] [] [Quartz.Core.QuartzScheduler] Scheduler QuartzScheduler_$_NON_CLUSTERED started.
but the cleanup never fires and the code that is supposed to be triggered between 1 to 10 min after initialization in OpenIddictQuartzConfiguration
options.AddTrigger(builder =>
{
// 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
// between 1 and 10 minutes after the application starts to ensure the job is executed at least once.
builder.ForJob(OpenIddictQuartzJob.Identity)
.WithSimpleSchedule(options => options.WithIntervalInHours(1).RepeatForever())
.WithDescription(SR.GetResourceString(SR.ID8002))
.StartAt(DateBuilder.FutureDate(new Random().Next(1, 10), IntervalUnit.Minute));
});
never runs.
What am I doing wrong here?
Issue Analytics
- State:
- Created a year ago
- Comments:13 (5 by maintainers)
Top GitHub Comments
Makes perfect sense, thank you for your time and all the fantastic work with this project.
Hi,
No, the pruning job doesn’t change the status and directly uses the
expiration_date
field to determine whether the expiration date has been reached or not.Try using
IOpenIddictTokenManager.PruneAsync()
andIOpenIddictAuthorizationManager.PruneAsync()
manually with the threshold of your choice to see if it correctly removes the expired tokens.