Merge branch 'feature/health-check-scheduler' of https://github.com/AndyButland/Umbraco-CMS into temp-U4-9984

This commit is contained in:
Jeavon Leopold
2017-06-05 11:17:01 +02:00
2 changed files with 35 additions and 7 deletions

View File

@@ -1,7 +1,9 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web.Http;
using Umbraco.Core.Configuration.HealthChecks;
using Umbraco.Web.Editors;
namespace Umbraco.Web.HealthCheck
@@ -12,10 +14,16 @@ namespace Umbraco.Web.HealthCheck
public class HealthCheckController : UmbracoAuthorizedJsonController
{
private readonly IHealthCheckResolver _healthCheckResolver;
private readonly IList<Guid> _disabledCheckIds;
public HealthCheckController()
{
_healthCheckResolver = HealthCheckResolver.Current;
var healthCheckConfig = (HealthChecksSection)ConfigurationManager.GetSection("umbracoConfiguration/HealthChecks");
_disabledCheckIds = healthCheckConfig.DisabledChecks
.Select(x => x.Id)
.ToList();
}
public HealthCheckController(IHealthCheckResolver healthCheckResolver)
@@ -30,6 +38,7 @@ namespace Umbraco.Web.HealthCheck
public object GetAllHealthChecks()
{
var groups = _healthCheckResolver.HealthChecks
.Where(x => _disabledCheckIds.Contains(x.Id) == false)
.GroupBy(x => x.Group)
.OrderBy(x => x.Key);
var healthCheckGroups = new List<HealthCheckGroup>();
@@ -51,9 +60,8 @@ namespace Umbraco.Web.HealthCheck
[HttpGet]
public object GetStatus(Guid id)
{
var check = _healthCheckResolver.HealthChecks.FirstOrDefault(x => x.Id == id);
if (check == null) throw new InvalidOperationException("No health check found with ID " + id);
var check = GetCheckById(id);
try
{
//Core.Logging.LogHelper.Debug<HealthCheckController>("Running health check: " + check.Name);
@@ -69,10 +77,19 @@ namespace Umbraco.Web.HealthCheck
[HttpPost]
public HealthCheckStatus ExecuteAction(HealthCheckAction action)
{
var check = _healthCheckResolver.HealthChecks.FirstOrDefault(x => x.Id == action.HealthCheckId);
if (check == null) throw new InvalidOperationException("No health check found with id " + action.HealthCheckId);
var check = GetCheckById(action.HealthCheckId);
return check.ExecuteAction(action);
}
private HealthCheck GetCheckById(Guid id)
{
var check = _healthCheckResolver.HealthChecks
.Where(x => _disabledCheckIds.Contains(x.Id) == false)
.FirstOrDefault(x => x.Id == id);
if (check == null) throw new InvalidOperationException(string.Format("No health check found with id {0}", id));
return check;
}
}
}