diff --git a/src/Umbraco.Core/Sync/DatabaseServerMessenger.cs b/src/Umbraco.Core/Sync/DatabaseServerMessenger.cs index b5236485c2..bf94324388 100644 --- a/src/Umbraco.Core/Sync/DatabaseServerMessenger.cs +++ b/src/Umbraco.Core/Sync/DatabaseServerMessenger.cs @@ -100,7 +100,7 @@ namespace Umbraco.Core.Sync /// Thread safety: this is NOT thread safe. Because it is NOT meant to run multi-threaded. /// Callers MUST ensure thread-safety. /// - internal protected void Boot() + protected void Boot() { // weight:10, must release *before* the facade service, because once released // the service will *not* be able to properly handle our notifications anymore diff --git a/src/Umbraco.Web/BatchedDatabaseServerMessenger.cs b/src/Umbraco.Web/BatchedDatabaseServerMessenger.cs index 09c7297ef2..aafa395518 100644 --- a/src/Umbraco.Web/BatchedDatabaseServerMessenger.cs +++ b/src/Umbraco.Web/BatchedDatabaseServerMessenger.cs @@ -21,10 +21,28 @@ namespace Umbraco.Web { public BatchedDatabaseServerMessenger(ApplicationContext appContext, bool enableDistCalls, DatabaseServerMessengerOptions options) : base(appContext, enableDistCalls, options) - { + { } + + // invoked by BatchedDatabaseServerMessengerStartup which is an ApplicationEventHandler + // with default "ShouldExecute", so that method will run if app IsConfigured and database + // context IsDatabaseConfigured - we still want to check CanConnect though to be safe + internal void Startup() + { + UmbracoModule.EndRequest += UmbracoModule_EndRequest; + UmbracoModule.RouteAttempt += UmbracoModule_RouteAttempt; + + if (ApplicationContext.DatabaseContext.CanConnect == false) + { + ApplicationContext.ProfilingLogger.Logger.Warn( + "Cannot connect to the database, distributed calls will not be enabled for this server."); + } + else + { + Boot(); + } } - internal void UmbracoModule_RouteAttempt(object sender, RoutableAttemptEventArgs e) + private void UmbracoModule_RouteAttempt(object sender, RoutableAttemptEventArgs e) { switch (e.Outcome) { @@ -47,7 +65,7 @@ namespace Umbraco.Web } } - internal void UmbracoModule_EndRequest(object sender, EventArgs e) + private void UmbracoModule_EndRequest(object sender, EventArgs e) { // will clear the batch - will remain in HttpContext though - that's ok FlushBatch(); @@ -116,8 +134,6 @@ namespace Umbraco.Web batch.Add(new RefreshInstructionEnvelope(servers, refresher, RefreshInstruction.GetInstructions(refresher, messageType, ids, idType, json))); - } - - + } } } \ No newline at end of file diff --git a/src/Umbraco.Web/BatchedDatabaseServerMessengerStartup.cs b/src/Umbraco.Web/BatchedDatabaseServerMessengerStartup.cs index 57b509a22e..a5b88a08ec 100644 --- a/src/Umbraco.Web/BatchedDatabaseServerMessengerStartup.cs +++ b/src/Umbraco.Web/BatchedDatabaseServerMessengerStartup.cs @@ -11,23 +11,12 @@ namespace Umbraco.Web { protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext) { - var msgr = ServerMessengerResolver.HasCurrent ? ServerMessengerResolver.Current.Messenger as BatchedDatabaseServerMessenger : null; + var messenger = ServerMessengerResolver.HasCurrent + ? ServerMessengerResolver.Current.Messenger as BatchedDatabaseServerMessenger + : null; - if (msgr == null) return; - - UmbracoModule.EndRequest += msgr.UmbracoModule_EndRequest; - UmbracoModule.RouteAttempt += msgr.UmbracoModule_RouteAttempt; - - if (applicationContext.DatabaseContext.IsDatabaseConfigured == false || applicationContext.DatabaseContext.CanConnect == false) - { - applicationContext.ProfilingLogger.Logger.Warn( - "The app cannot connect to the database, this server cannot be initialized with " - + typeof(BatchedDatabaseServerMessenger) + ", distributed calls will not be enabled for this server"); - } - else - { - msgr.Boot(); - } + if (messenger != null) + messenger.Startup(); } } } \ No newline at end of file