Files
Umbraco-CMS/src/Umbraco.Infrastructure/Suspendable.cs
Shannon Deminick eba6373a12 Examine 2.0 integration (#10241)
* Init commit for examine 2.0 work, most old umb examine tests working, probably a lot that doesn't

* Gets Umbraco Examine tests passing and makes some sense out of them, fixes some underlying issues.

* Large refactor, remove TaskHelper, rename Notifications to be consistent, Gets all examine/lucene indexes building and startup ordered in the correct way, removes old files, creates new IUmbracoIndexingHandler for abstracting out all index operations for umbraco data, abstracts out IIndexRebuilder, Fixes Stack overflow with LiveModelsProvider and loading assemblies, ports some changes from v8 for startup handling with cold boots, refactors out LastSyncedFileManager

* fix up issues with rebuilding and management dashboard.

* removes old files, removes NetworkHelper, fixes LastSyncedFileManager implementation to ensure the machine name is used, fix up logging with cold boot state.

* Makes MainDom safer to use and makes PublishedSnapshotService lazily register with MainDom

* lazily acquire application id (fix unit tests)

* Fixes resource casing and missing test file

* Ensures caches when requiring internal services for PublishedSnapshotService, UseNuCache is a separate call, shouldn't be buried in AddWebComponents, was also causing issues in integration tests since nucache was being used for the Id2Key service.

* For UmbracoTestServerTestBase enable nucache services

* Fixing tests

* Fix another test

* Fixes tests, use TestHostingEnvironment, make Tests.Common use net5, remove old Lucene.Net.Contrib ref.

* Fixes up some review notes

* Fixes issue with doubly registering PublishedSnapshotService meanig there could be 2x instances of it

* Checks for parseexception when executing the query

* Use application root instead of duplicating functionality.

* Added Examine project to netcore only solution file

* Fixed casing issue with LazyLoad, that is not lowercase.

* uses cancellationToken instead of bool flag, fixes always reading lastId from the LastSyncedFileManager, fixes RecurringHostedServiceBase so that there isn't an overlapping thread for the same task type

* Fix tests

* remove legacy test project from solution file

* Fix test

Co-authored-by: Bjarke Berg <mail@bergmania.dk>
2021-05-18 10:31:38 +02:00

120 lines
3.6 KiB
C#

using Microsoft.Extensions.Logging;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Cache;
using Umbraco.Cms.Infrastructure.Examine;
namespace Umbraco.Cms.Infrastructure
{
public static class Suspendable
{
public static class PageCacheRefresher
{
private static bool s_tried, s_suspended;
public static bool CanRefreshDocumentCacheFromDatabase
{
get
{
// trying a full refresh
if (s_suspended == false)
{
return true;
}
s_tried = true; // remember we tried
return false;
}
}
// trying a partial update
// ok if not suspended, or if we haven't done a full already
public static bool CanUpdateDocumentCache => s_suspended == false || s_tried == false;
public static void SuspendDocumentCache()
{
StaticApplicationLogging.Logger.LogInformation("Suspend document cache.");
s_suspended = true;
}
public static void ResumeDocumentCache(CacheRefresherCollection cacheRefresherCollection)
{
s_suspended = false;
StaticApplicationLogging.Logger.LogInformation("Resume document cache (reload:{Tried}).", s_tried);
if (s_tried == false)
{
return;
}
s_tried = false;
ICacheRefresher pageRefresher = cacheRefresherCollection[ContentCacheRefresher.UniqueId];
pageRefresher.RefreshAll();
}
}
//This is really needed at all since the only place this is used is in ExamineComponent and that already maintains a flag of whether it suspsended or not
// AHH... but Deploy probably uses this?
public static class ExamineEvents
{
private static bool s_tried, s_suspended;
public static bool CanIndex
{
get
{
if (s_suspended == false)
{
return true;
}
s_tried = true; // remember we tried
return false;
}
}
public static void SuspendIndexers(ILogger logger)
{
logger.LogInformation("Suspend indexers.");
s_suspended = true;
}
public static void ResumeIndexers(ExamineIndexRebuilder backgroundIndexRebuilder)
{
s_suspended = false;
StaticApplicationLogging.Logger.LogInformation("Resume indexers (rebuild:{Tried}).", s_tried);
if (s_tried == false)
{
return;
}
s_tried = false;
backgroundIndexRebuilder.RebuildIndexes(false);
}
}
public static class ScheduledPublishing
{
private static bool s_suspended;
public static bool CanRun => s_suspended == false;
public static void Suspend()
{
StaticApplicationLogging.Logger.LogInformation("Suspend scheduled publishing.");
s_suspended = true;
}
public static void Resume()
{
StaticApplicationLogging.Logger.LogInformation("Resume scheduled publishing.");
s_suspended = false;
}
}
}
}