diff --git a/src/Umbraco.Web/Scheduling/KeepAlive.cs b/src/Umbraco.Web/Scheduling/KeepAlive.cs index 763e28b608..f4beb9d5b8 100644 --- a/src/Umbraco.Web/Scheduling/KeepAlive.cs +++ b/src/Umbraco.Web/Scheduling/KeepAlive.cs @@ -6,6 +6,7 @@ using System.Threading.Tasks; using Umbraco.Core; using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.Logging; +using Umbraco.Core.Sync; namespace Umbraco.Web.Scheduling { @@ -20,9 +21,21 @@ namespace Umbraco.Web.Scheduling _appContext = appContext; } + private ILogger Logger { get { return _appContext.ProfilingLogger.Logger; } } + public override async Task PerformRunAsync(CancellationToken token) { if (_appContext == null) return true; // repeat... + + switch (_appContext.GetCurrentServerRole()) + { + case ServerRole.Slave: + Logger.Debug("Does not run on slave servers."); + return true; // DO repeat, server role can change + case ServerRole.Unknown: + Logger.Debug("Does not run on servers with unknown role."); + return true; // DO repeat, server role can change + } // ensure we do not run if not main domain, but do NOT lock it if (_appContext.MainDom.IsMainDom == false) @@ -31,7 +44,7 @@ namespace Umbraco.Web.Scheduling return false; // do NOT repeat, going down } - using (DisposableTimer.DebugDuration(() => "Keep alive executing", () => "Keep alive complete")) + using (_appContext.ProfilingLogger.DebugDuration("Keep alive executing", "Keep alive complete")) { string umbracoAppUrl = null; diff --git a/src/Umbraco.Web/Scheduling/ScheduledPublishing.cs b/src/Umbraco.Web/Scheduling/ScheduledPublishing.cs index f8ff7e7080..919a531549 100644 --- a/src/Umbraco.Web/Scheduling/ScheduledPublishing.cs +++ b/src/Umbraco.Web/Scheduling/ScheduledPublishing.cs @@ -31,7 +31,7 @@ namespace Umbraco.Web.Scheduling private ILogger Logger { get { return _appContext.ProfilingLogger.Logger; } } - public override async Task PerformRunAsync(CancellationToken token) + public override bool PerformRun() { if (_appContext == null) return true; // repeat... @@ -55,16 +55,18 @@ namespace Umbraco.Web.Scheduling return false; // do NOT repeat, going down } + UmbracoContext tempContext = null; try { // DO not run publishing if content is re-loading if (content.Instance.isInitializing == false) { //TODO: We should remove this in v8, this is a backwards compat hack + // see notes in CacheRefresherEventHandler // because notifications will not be sent if there is no UmbracoContext // see NotificationServiceExtensions var httpContext = new HttpContextWrapper(new HttpContext(new SimpleWorkerRequest("temp.aspx", "", new StringWriter()))); - UmbracoContext.EnsureContext( + tempContext = UmbracoContext.EnsureContext( httpContext, _appContext, new WebSecurity(httpContext, _appContext), @@ -81,13 +83,18 @@ namespace Umbraco.Web.Scheduling { Logger.Error("Failed (see exception).", e); } + finally + { + if (tempContext != null) + tempContext.Dispose(); // nulls the ThreadStatic context + } return true; // repeat } public override bool IsAsync { - get { return true; } + get { return false; } } } } \ No newline at end of file