From 1fd020a0f2cf47d113e22405475b1c6cdbfdd33c Mon Sep 17 00:00:00 2001 From: Shannon Date: Thu, 11 Aug 2016 14:33:10 +0200 Subject: [PATCH] adds better debug logging to scheduled publishing --- .../Publishing/ScheduledPublisher.cs | 23 +++++++++++-- .../Scheduling/ScheduledPublishing.cs | 34 +++++++++++++------ .../WebServices/ScheduledPublishController.cs | 7 +++- 3 files changed, 49 insertions(+), 15 deletions(-) diff --git a/src/Umbraco.Core/Publishing/ScheduledPublisher.cs b/src/Umbraco.Core/Publishing/ScheduledPublisher.cs index 45492423ab..94df1b88f1 100644 --- a/src/Umbraco.Core/Publishing/ScheduledPublisher.cs +++ b/src/Umbraco.Core/Publishing/ScheduledPublisher.cs @@ -17,8 +17,15 @@ namespace Umbraco.Core.Publishing _contentService = contentService; } - public void CheckPendingAndProcess() + /// + /// Processes scheduled operations + /// + /// + /// Returns the number of items successfully completed + /// + public int CheckPendingAndProcess() { + var counter = 0; foreach (var d in _contentService.GetContentForRelease()) { try @@ -32,10 +39,14 @@ namespace Umbraco.Core.Publishing LogHelper.Error("Could not published the document (" + d.Id + ") based on it's scheduled release, status result: " + result.Result.StatusType, result.Exception); } else - { + { LogHelper.Warn("Could not published the document (" + d.Id + ") based on it's scheduled release. Status result: " + result.Result.StatusType); } } + else + { + counter++; + } } catch (Exception ee) { @@ -48,7 +59,11 @@ namespace Umbraco.Core.Publishing try { d.ExpireDate = null; - _contentService.UnPublish(d, (int)d.GetWriterProfile().Id); + var result = _contentService.UnPublish(d, (int)d.GetWriterProfile().Id); + if (result) + { + counter++; + } } catch (Exception ee) { @@ -56,6 +71,8 @@ namespace Umbraco.Core.Publishing throw; } } + + return counter; } } } \ No newline at end of file diff --git a/src/Umbraco.Web/Scheduling/ScheduledPublishing.cs b/src/Umbraco.Web/Scheduling/ScheduledPublishing.cs index 0f7e3f0183..6649c3c474 100644 --- a/src/Umbraco.Web/Scheduling/ScheduledPublishing.cs +++ b/src/Umbraco.Web/Scheduling/ScheduledPublishing.cs @@ -49,20 +49,32 @@ namespace Umbraco.Web.Scheduling return false; // do NOT repeat, going down } - using (DisposableTimer.DebugDuration(() => "Scheduled publishing executing", () => "Scheduled publishing complete")) + string umbracoAppUrl; + try { - string umbracoAppUrl = null; - - try + umbracoAppUrl = _appContext == null || _appContext.UmbracoApplicationUrl.IsNullOrWhiteSpace() + ? null + : _appContext.UmbracoApplicationUrl; + if (umbracoAppUrl.IsNullOrWhiteSpace()) { - umbracoAppUrl = _appContext.UmbracoApplicationUrl; - if (umbracoAppUrl.IsNullOrWhiteSpace()) - { - LogHelper.Warn("No url for service (yet), skip."); - return true; // repeat - } + LogHelper.Warn("No url for service (yet), skip."); + return true; // repeat + } + } + catch (Exception e) + { + LogHelper.Error("Could not acquire application url", e); + return true; // repeat + } - var url = umbracoAppUrl + "/RestServices/ScheduledPublish/Index"; + var url = umbracoAppUrl + "/RestServices/ScheduledPublish/Index"; + + using (DisposableTimer.DebugDuration( + () => string.Format("Scheduled publishing executing @ {0}", url), + () => "Scheduled publishing complete")) + { + try + { using (var wc = new HttpClient()) { var request = new HttpRequestMessage(HttpMethod.Post, url) diff --git a/src/Umbraco.Web/WebServices/ScheduledPublishController.cs b/src/Umbraco.Web/WebServices/ScheduledPublishController.cs index 0ab76738dc..fcf07126fb 100644 --- a/src/Umbraco.Web/WebServices/ScheduledPublishController.cs +++ b/src/Umbraco.Web/WebServices/ScheduledPublishController.cs @@ -19,7 +19,11 @@ namespace Umbraco.Web.WebServices public JsonResult Index() { if (_isPublishingRunning) + { + Logger.Debug(() => "Scheduled publishing is currently executing this request will exit"); return null; + } + _isPublishingRunning = true; try @@ -28,7 +32,8 @@ namespace Umbraco.Web.WebServices if (content.Instance.isInitializing == false) { var publisher = new ScheduledPublisher(Services.ContentService); - publisher.CheckPendingAndProcess(); + var count = publisher.CheckPendingAndProcess(); + Logger.Debug(() => string.Format("The scheduler processed {0} items", count)); } return Json(new