question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Quartz needs reference to Quartz.Extensions.Hosting

See original GitHub issue

Hi, great job on the new version.

I believe OpenIddict.Quartz is missing a reference to Quartz.Extensions.Hosting . Currently, without referencing this package separately, then

services.AddQuartzHostedService(options => options.WaitForJobsToComplete = true);

won’t work. (Right now, OpenIddict.Quartz depends on Quartz.Extensions.DependincyInjection which in turn depends on the core Quartz package, but the Quartz.Extensions.Hosting package is not present.)

Thanks.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
kevinchaletcommented, Nov 17, 2020

@lahma thanks for chiming in, much appreciated!

As you said, there’s likely no right answer here. As such, I’m going to leave things as-is for now. If we ever decide to make Quartz.NET a first-class citizen by adding OpenIddict.Quartz to the OpenIddict metapackage, we’ll still be able to revisit that.

Thanks!

0reactions
Camuvingiancommented, Jul 15, 2022

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; }); 
		});
	})

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? I image something stupid…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Hosted Services Integration
You can add Quartz configuration by invoking an extension method AddQuartzHostedService on IServiceCollection . This will add a hosted Quartz ...
Read more >
Microsoft DI Integration | Quartz.NET
Quartz.Extensions.Hosting allows you to have a background service for your application that handles starting and stopping the scheduler. Example ...
Read more >
Using Quartz.NET with ASP.NET Core and worker services
In this post I show how to run Quartz.NET jobs in ASP.NET Core and worker service apps using the Quartz.Extensions.Hosting package.
Read more >
Creating a Quartz.NET hosted service with ASP.NET Core
In this post I describe how to run Quartz.NET jobs using an ASP.NET Core hosted service, and how to handle scoped services inside...
Read more >
Quartz.aspnetcore and hosting in ASP.NET Core
1 Answer. According to this article, you could find the AddQuartz is used to add base Quartz scheduler, job and trigger configuration(configure ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found