Removed unused ctor (just for tests) + Fixed a couple of handlers that is not intended to execute before runtime level = run.

This commit is contained in:
Bjarke Berg
2021-05-20 13:16:50 +02:00
parent 0a3b39cc38
commit 9b2cf8422d
3 changed files with 23 additions and 32 deletions

View File

@@ -38,19 +38,19 @@ namespace Umbraco.Cms.Core.Cache
/// <inheritdoc/>
public void Handle(UmbracoApplicationStartingNotification notification)
{
if (_runtimeState.Level < RuntimeLevel.Run)
{
return;
}
if (_databaseFactory.CanConnect == false)
{
_logger.LogWarning("Cannot connect to the database, distributed calls will not be enabled for this server.");
}
else if (_runtimeState.Level != RuntimeLevel.Run)
{
_logger.LogWarning("Distributed calls are not available outside the Run runtime level");
}
else
{
// Sync on startup, this will run through the messenger's initialization sequence
_messenger?.Sync();
return;
}
// Sync on startup, this will run through the messenger's initialization sequence
_messenger?.Sync();
}
/// <summary>

View File

@@ -1,7 +1,9 @@
using System;
using System.Threading;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Events;
using Umbraco.Cms.Core.Notifications;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Sync;
namespace Umbraco.Cms.Infrastructure.Examine
@@ -17,6 +19,7 @@ namespace Umbraco.Cms.Infrastructure.Examine
{
private readonly ISyncBootStateAccessor _syncBootStateAccessor;
private readonly ExamineIndexRebuilder _backgroundIndexRebuilder;
private readonly IRuntimeState _runtimeState;
// These must be static because notification handlers are transient.
// this does unfortunatley mean that one RebuildOnStartupHandler instance
@@ -30,10 +33,12 @@ namespace Umbraco.Cms.Infrastructure.Examine
public RebuildOnStartupHandler(
ISyncBootStateAccessor syncBootStateAccessor,
ExamineIndexRebuilder backgroundIndexRebuilder)
ExamineIndexRebuilder backgroundIndexRebuilder,
IRuntimeState runtimeState)
{
_syncBootStateAccessor = syncBootStateAccessor;
_backgroundIndexRebuilder = backgroundIndexRebuilder;
_runtimeState = runtimeState;
}
/// <summary>
@@ -41,7 +46,13 @@ namespace Umbraco.Cms.Infrastructure.Examine
/// </summary>
/// <param name="notification"></param>
public void Handle(UmbracoRequestBeginNotification notification)
=> LazyInitializer.EnsureInitialized(
{
if (_runtimeState.Level < RuntimeLevel.Run)
{
return;
}
LazyInitializer.EnsureInitialized(
ref _isReady,
ref _isReadSet,
ref _isReadyLock,
@@ -56,5 +67,6 @@ namespace Umbraco.Cms.Infrastructure.Examine
return true;
});
}
}
}

View File

@@ -112,27 +112,6 @@ namespace Umbraco.Cms.Infrastructure.Persistence
Configure(settings.ConnectionString, settings.ProviderName);
}
/// <summary>
/// Initializes a new instance of the <see cref="UmbracoDatabaseFactory"/>.
/// </summary>
/// <remarks>Used in tests.</remarks>
public UmbracoDatabaseFactory(ILogger<UmbracoDatabaseFactory> logger, ILoggerFactory loggerFactory, string connectionString, string providerName, Lazy<IMapperCollection> mappers, IDbProviderFactoryCreator dbProviderFactoryCreator, DatabaseSchemaCreatorFactory databaseSchemaCreatorFactory)
{
_mappers = mappers ?? throw new ArgumentNullException(nameof(mappers));
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
_loggerFactory = loggerFactory;
_dbProviderFactoryCreator = dbProviderFactoryCreator ?? throw new ArgumentNullException(nameof(dbProviderFactoryCreator));
_databaseSchemaCreatorFactory = databaseSchemaCreatorFactory ?? throw new ArgumentNullException(nameof(databaseSchemaCreatorFactory));
if (string.IsNullOrWhiteSpace(connectionString) || string.IsNullOrWhiteSpace(providerName))
{
logger.LogDebug("Missing connection string or provider name, defer configuration.");
return; // not configured
}
Configure(connectionString, providerName);
}
#endregion
/// <inheritdoc />