adds logging to scheduled bits

This commit is contained in:
Shannon
2014-06-25 11:00:11 +10:00
parent 65ea6f94d3
commit e27163f3a7
5 changed files with 107 additions and 91 deletions

View File

@@ -224,7 +224,7 @@
</scheduledTasks>
<!-- distributed calls must be enabled when using Umbraco in a load balanced environment -->
<distributedCall enable="true">
<distributedCall enable="false">
<!-- the id of the user who's making the calls -->
<!-- needed for security, umbraco will automatically look up correct login and passwords -->
<user>0</user>
@@ -263,10 +263,7 @@
<server serverName="MyServer">server1.mysite.com</server>
<server appId="/LM/W3SVC/69/ROOT">server1.mysite.com</server>
-->
<server forcePortnumber="6210" appId="/LM/W3SVC/69/ROOT">localhost</server>
<server>umb1.dev</server>
<server>umb2.dev</server>
</servers>
</distributedCall>

View File

@@ -10,26 +10,30 @@ namespace Umbraco.Web.Scheduling
{
public static void Start(object sender)
{
//NOTE: sender will be the umbraco ApplicationContext
var appContext = sender as ApplicationContext;
if (appContext == null) return;
var umbracoBaseUrl = ServerEnvironmentHelper.GetCurrentServerUmbracoBaseUrl();
var url = string.Format("{0}/ping.aspx", umbracoBaseUrl);
try
using (DisposableTimer.DebugDuration<KeepAlive>(() => "Keep alive executing", () => "Keep alive complete"))
{
using (var wc = new WebClient())
//NOTE: sender will be the umbraco ApplicationContext
var appContext = sender as ApplicationContext;
if (appContext == null) return;
var umbracoBaseUrl = ServerEnvironmentHelper.GetCurrentServerUmbracoBaseUrl();
var url = string.Format("{0}/ping.aspx", umbracoBaseUrl);
try
{
wc.DownloadString(url);
using (var wc = new WebClient())
{
wc.DownloadString(url);
}
}
catch (Exception ee)
{
LogHelper.Error<KeepAlive>("Error in ping", ee);
}
}
catch (Exception ee)
{
LogHelper.Error<KeepAlive>("Error in ping", ee);
}
}
}
}

View File

@@ -16,35 +16,38 @@ namespace Umbraco.Web.Scheduling
public void Start(object sender)
{
//NOTE: sender will be the umbraco ApplicationContext
using (DisposableTimer.DebugDuration<ScheduledPublishing>(() => "Scheduled publishing executing", () => "Scheduled publishing complete"))
{
//NOTE: sender will be the umbraco ApplicationContext
var appContext = sender as ApplicationContext;
if (appContext == null) return;
var appContext = sender as ApplicationContext;
if (appContext == null) return;
if (_isPublishingRunning) return;
if (_isPublishingRunning) return;
_isPublishingRunning = true;
_isPublishingRunning = true;
try
{
var umbracoBaseUrl = ServerEnvironmentHelper.GetCurrentServerUmbracoBaseUrl();
var url = string.Format("{0}/RestServices/ScheduledPublish/", umbracoBaseUrl);
using (var wc = new WebClient())
try
{
//pass custom the authorization header
wc.Headers.Set("Authorization", AdminTokenAuthorizeAttribute.GetAuthHeaderTokenVal(appContext));
var umbracoBaseUrl = ServerEnvironmentHelper.GetCurrentServerUmbracoBaseUrl();
var url = string.Format("{0}/RestServices/ScheduledPublish/", umbracoBaseUrl);
using (var wc = new WebClient())
{
//pass custom the authorization header
wc.Headers.Set("Authorization", AdminTokenAuthorizeAttribute.GetAuthHeaderTokenVal(appContext));
var result = wc.UploadString(url, "");
var result = wc.UploadString(url, "");
}
}
}
catch (Exception ee)
{
LogHelper.Error<ScheduledPublishing>("An error occurred with the scheduled publishing", ee);
}
finally
{
_isPublishingRunning = false;
}
catch (Exception ee)
{
LogHelper.Error<ScheduledPublishing>("An error occurred with the scheduled publishing", ee);
}
finally
{
_isPublishingRunning = false;
}
}
}

View File

@@ -6,6 +6,7 @@ using Umbraco.Core.Configuration;
using Umbraco.Core.Logging;
using Umbraco.Core.Publishing;
using Umbraco.Core.Sync;
using Umbraco.Core;
namespace Umbraco.Web.Scheduling
{
@@ -19,24 +20,28 @@ namespace Umbraco.Web.Scheduling
public void Start(object sender)
{
//NOTE: sender will be the umbraco ApplicationContext
using (DisposableTimer.DebugDuration<ScheduledTasks>(() => "Scheduled tasks executing", () => "Scheduled tasks complete"))
{
//NOTE: sender will be the umbraco ApplicationContext
if (_isPublishingRunning) return;
if (_isPublishingRunning) return;
_isPublishingRunning = true;
_isPublishingRunning = true;
try
{
ProcessTasks();
}
catch (Exception ee)
{
LogHelper.Error<ScheduledTasks>("Error executing scheduled task", ee);
}
finally
{
_isPublishingRunning = false;
try
{
ProcessTasks();
}
catch (Exception ee)
{
LogHelper.Error<ScheduledTasks>("Error executing scheduled task", ee);
}
finally
{
_isPublishingRunning = false;
}
}
}
private static void ProcessTasks()

View File

@@ -1,5 +1,6 @@
using System.Threading;
using Umbraco.Core;
using Umbraco.Core.Logging;
using Umbraco.Core.Sync;
namespace Umbraco.Web.Scheduling
@@ -13,10 +14,10 @@ namespace Umbraco.Web.Scheduling
/// in a web project nowadays.
///
/// </remarks>
internal sealed class Scheduler : ApplicationEventHandler
{
private Timer _pingTimer;
private Timer _schedulingTimer;
internal sealed class Scheduler : ApplicationEventHandler
{
private Timer _pingTimer;
private Timer _schedulingTimer;
private LogScrubber _scrubber;
protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
@@ -24,23 +25,23 @@ namespace Umbraco.Web.Scheduling
if (umbracoApplication.Context == null)
return;
// time to setup the tasks
// time to setup the tasks
// these are the legacy tasks
// just copied over here for backward compatibility
// of course we should have a proper scheduler, see #U4-809
// these are the legacy tasks
// just copied over here for backward compatibility
// of course we should have a proper scheduler, see #U4-809
// ping/keepalive
// ping/keepalive
_pingTimer = new Timer(KeepAlive.Start, applicationContext, 60000, 300000);
// scheduled publishing/unpublishing
// scheduled publishing/unpublishing
_schedulingTimer = new Timer(PerformScheduling, applicationContext, 30000, 60000);
//log scrubbing
_scrubber = new LogScrubber();
_scrubber.Start();
}
}
/// <summary>
/// This performs all of the scheduling on the one timer
@@ -51,32 +52,38 @@ namespace Umbraco.Web.Scheduling
/// </remarks>
private static void PerformScheduling(object sender)
{
//get the current server status to see if this server should execute the scheduled publishing
var serverStatus = ServerEnvironmentHelper.GetStatus();
switch (serverStatus)
using (DisposableTimer.DebugDuration<Scheduler>(() => "Scheduling interval executing", () => "Scheduling interval complete"))
{
case CurrentServerEnvironmentStatus.Single:
case CurrentServerEnvironmentStatus.Master:
case CurrentServerEnvironmentStatus.Unknown:
//if it's a single server install, a master or it cannot be determined
// then we will process the scheduling
//get the current server status to see if this server should execute the scheduled publishing
var serverStatus = ServerEnvironmentHelper.GetStatus();
switch (serverStatus)
{
case CurrentServerEnvironmentStatus.Single:
case CurrentServerEnvironmentStatus.Master:
case CurrentServerEnvironmentStatus.Unknown:
//if it's a single server install, a master or it cannot be determined
// then we will process the scheduling
//do the scheduled publishing
var scheduledPublishing = new ScheduledPublishing();
scheduledPublishing.Start(sender);
//do the scheduled publishing
var scheduledPublishing = new ScheduledPublishing();
scheduledPublishing.Start(sender);
//do the scheduled tasks
var scheduledTasks = new ScheduledTasks();
scheduledTasks.Start(sender);
//do the scheduled tasks
var scheduledTasks = new ScheduledTasks();
scheduledTasks.Start(sender);
break;
case CurrentServerEnvironmentStatus.Slave:
//do not process
break;
break;
case CurrentServerEnvironmentStatus.Slave:
//do not process
LogHelper.Debug<Scheduler>(
() => string.Format("Current server ({0}) detected as a slave, no scheduled processes will execute on this server", NetworkHelper.MachineName));
break;
}
}
}
}
}
}