OrchardCMS / OrchardCore

Orchard Core is an open-source modular and multi-tenant application framework built with ASP.NET Core, and a content management system (CMS) built on top of that framework.
https://orchardcore.net
BSD 3-Clause "New" or "Revised" License
7.23k stars 2.34k forks source link

Stop OpenIdBackgroundTask from running on multiple instances #13109

Open KWC252 opened 1 year ago

KWC252 commented 1 year ago

Every 30 minutes we're seeing a spike of certificate calls coming from OrchardCore's OpenIdBackgroundTask. Each certificate is requested up to 24 times during a spike, which only takes about a second. We think part of the problem could be that it's running on all our instances every 30 minutes. This thread says it's possible to prevent a background task from running on multiple instances, but it's for a custom task:

https://github.com/OrchardCMS/OrchardCore/issues/11463

I don't want to modify the OrchardCore code. Is there a way to change the lock settings for this background task through a recipe? Thanks.

jtkech commented 1 year ago

Is there a way to change the lock settings for this background task through a recipe?

I don't think you can do that through a recipe but can be done through the Admin UI if you enable the OC.BackgroundTasks feature, and where you can also change the period of the task or disable it.

Otherwise nothing more to add to the comments of #11463, yes we don't have yet ootb a way to give the ownership to only one instance (need custom code), we can only prevent a task to be run by multiple instances at the same time, but each instance can still run the task one after each other.

Note: To have a distributed lock you need e.g. the RedisLock feature and a Redis instance running.

KWC252 commented 1 year ago

I'll look into a solution using custom code with RedisLock - unfortunately, we can't rely on the Admin UI for this, we'd have to manually change the task settings across a lot of sites. Thanks for getting back to me so quickly on this.

ShaneCourtrille commented 1 year ago

Related to #13262