U4-10538 Disable Ping on front-end nodes when load balancing

(cherry picked from commit fd8daa398f)
This commit is contained in:
Shannon
2017-10-16 16:22:10 +11:00
committed by Sebastiaan Janssen
parent e84a963d66
commit 7cbaecc53a
2 changed files with 24 additions and 4 deletions

View File

@@ -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<bool> PerformRunAsync(CancellationToken token)
{
if (_appContext == null) return true; // repeat...
switch (_appContext.GetCurrentServerRole())
{
case ServerRole.Slave:
Logger.Debug<ScheduledPublishing>("Does not run on slave servers.");
return true; // DO repeat, server role can change
case ServerRole.Unknown:
Logger.Debug<ScheduledPublishing>("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<KeepAlive>(() => "Keep alive executing", () => "Keep alive complete"))
using (_appContext.ProfilingLogger.DebugDuration<KeepAlive>("Keep alive executing", "Keep alive complete"))
{
string umbracoAppUrl = null;

View File

@@ -31,7 +31,7 @@ namespace Umbraco.Web.Scheduling
private ILogger Logger { get { return _appContext.ProfilingLogger.Logger; } }
public override async Task<bool> 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<ScheduledPublishing>("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; }
}
}
}