Skip to content

Commit 09b3bd1

Browse files
mattbrailsfordkjacAndyButland
authored
v14: Async healthchecks (#17090)
* Make block editor base classes public * Update BlockEditorValues.cs Change to trigger a new build for #16774 * Make healthchecks fully async * Updated obsolete comments to reference next but one major. --------- Co-authored-by: Kenn Jacobsen <[email protected]> Co-authored-by: Andy Butland <[email protected]>
1 parent def9bd0 commit 09b3bd1

File tree

17 files changed

+63
-20
lines changed

17 files changed

+63
-20
lines changed

src/Umbraco.Cms.Api.Management/Controllers/HealthCheck/ExecuteActionHealthCheckController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public async Task<ActionResult<HealthCheckResultResponseModel>> ExecuteAction(
6161
return BadRequest(invalidModelProblem);
6262
}
6363

64-
HealthCheckStatus result = healthCheck.ExecuteAction(_umbracoMapper.Map<HealthCheckAction>(action)!);
64+
HealthCheckStatus result = await healthCheck.ExecuteActionAsync(_umbracoMapper.Map<HealthCheckAction>(action)!);
6565

6666
return await Task.FromResult(Ok(_umbracoMapper.Map<HealthCheckResultResponseModel>(result)));
6767
}

src/Umbraco.Cms.Api.Management/Controllers/HealthCheck/Group/CheckHealthCheckGroupController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,6 @@ public async Task<IActionResult> ByNameWithResult(
3939
return HealthCheckGroupNotFound();
4040
}
4141

42-
return await Task.FromResult(Ok(_healthCheckGroupPresentationFactory.CreateHealthCheckGroupWithResultViewModel(group)));
42+
return Ok(await _healthCheckGroupPresentationFactory.CreateHealthCheckGroupWithResultViewModelAsync(group));
4343
}
4444
}

src/Umbraco.Cms.Api.Management/Factories/HealthCheckGroupPresentationFactory.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace Umbraco.Cms.Api.Management.Factories;
99

10+
// TODO (V16): Make internal sealed.
1011
public class HealthCheckGroupPresentationFactory : IHealthCheckGroupPresentationFactory
1112
{
1213
private readonly HealthChecksSettings _healthChecksSettings;
@@ -40,13 +41,21 @@ public HealthCheckGroupPresentationFactory(
4041
return groups;
4142
}
4243

44+
[Obsolete("Use CreateHealthCheckGroupWithResultViewModelAsync instead. Will be removed in v17.")]
4345
public HealthCheckGroupWithResultResponseModel CreateHealthCheckGroupWithResultViewModel(IGrouping<string?, HealthCheck> healthCheckGroup)
46+
=> CreateHealthCheckGroupWithResultViewModelAsync(healthCheckGroup).GetAwaiter().GetResult();
47+
48+
[Obsolete("Use CreateHealthCheckGroupWithResultViewModelAsync instead. Will be removed in v17.")]
49+
public HealthCheckWithResultPresentationModel CreateHealthCheckWithResultViewModel(HealthCheck healthCheck) =>
50+
CreateHealthCheckWithResultViewModelAsync(healthCheck).GetAwaiter().GetResult();
51+
52+
public async Task<HealthCheckGroupWithResultResponseModel> CreateHealthCheckGroupWithResultViewModelAsync(IGrouping<string?, HealthCheck> healthCheckGroup)
4453
{
4554
var healthChecks = new List<HealthCheckWithResultPresentationModel>();
4655

4756
foreach (HealthCheck healthCheck in healthCheckGroup)
4857
{
49-
healthChecks.Add(CreateHealthCheckWithResultViewModel(healthCheck));
58+
healthChecks.Add(await CreateHealthCheckWithResultViewModelAsync(healthCheck));
5059
}
5160

5261
var healthCheckGroupViewModel = new HealthCheckGroupWithResultResponseModel
@@ -57,11 +66,11 @@ public HealthCheckGroupWithResultResponseModel CreateHealthCheckGroupWithResultV
5766
return healthCheckGroupViewModel;
5867
}
5968

60-
public HealthCheckWithResultPresentationModel CreateHealthCheckWithResultViewModel(HealthCheck healthCheck)
69+
public async Task<HealthCheckWithResultPresentationModel> CreateHealthCheckWithResultViewModelAsync(HealthCheck healthCheck)
6170
{
6271
_logger.LogDebug($"Running health check: {healthCheck.Name}");
6372

64-
IEnumerable<HealthCheckStatus> results = healthCheck.GetStatus().Result;
73+
IEnumerable<HealthCheckStatus> results = await healthCheck.GetStatusAsync();
6574

6675
var healthCheckViewModel = new HealthCheckWithResultPresentationModel
6776
{

src/Umbraco.Cms.Api.Management/Factories/IHealthCheckGroupPresentationFactory.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,19 @@ public interface IHealthCheckGroupPresentationFactory
77
{
88
IEnumerable<IGrouping<string?, HealthCheck>> CreateGroupingFromHealthCheckCollection();
99

10+
[Obsolete("Use CreateHealthCheckGroupWithResultViewModelAsync instead. Will be removed in v17.")]
1011
HealthCheckGroupWithResultResponseModel CreateHealthCheckGroupWithResultViewModel(IGrouping<string?, HealthCheck> healthCheckGroup);
1112

13+
[Obsolete("Use CreateHealthCheckGroupWithResultViewModelAsync instead. Will be removed in v17.")]
1214
HealthCheckWithResultPresentationModel CreateHealthCheckWithResultViewModel(HealthCheck healthCheck);
15+
16+
Task<HealthCheckGroupWithResultResponseModel> CreateHealthCheckGroupWithResultViewModelAsync(IGrouping<string?, HealthCheck> healthCheckGroup)
17+
#pragma warning disable CS0618 // Type or member is obsolete
18+
=> Task.FromResult(CreateHealthCheckGroupWithResultViewModel(healthCheckGroup));
19+
#pragma warning restore CS0618 // Type or member is obsolete
20+
21+
Task<HealthCheckWithResultPresentationModel> CreateHealthCheckWithResultViewModelAsync(HealthCheck healthCheck)
22+
#pragma warning disable CS0618 // Type or member is obsolete
23+
=> Task.FromResult(CreateHealthCheckWithResultViewModel(healthCheck));
24+
#pragma warning restore CS0618 // Type or member is obsolete
1325
}

src/Umbraco.Core/HealthChecks/Checks/AbstractSettingsCheck.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public abstract class AbstractSettingsCheck : HealthCheck
6363
"healthcheck", "checkErrorMessageUnexpectedValue", new[] { CurrentValue, Values.First(v => v.IsRecommended).Value, ItemPath });
6464

6565
/// <inheritdoc />
66-
public override Task<IEnumerable<HealthCheckStatus>> GetStatus()
66+
public override Task<IEnumerable<HealthCheckStatus>> GetStatusAsync()
6767
{
6868
// update the successMessage with the CurrentValue
6969
var successMessage = string.Format(CheckSuccessMessage, ItemPath, Values, CurrentValue);

src/Umbraco.Core/HealthChecks/Checks/Data/DatabaseIntegrityCheck.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public DatabaseIntegrityCheck(
3838
/// <summary>
3939
/// Get the status for this health check
4040
/// </summary>
41-
public override Task<IEnumerable<HealthCheckStatus>> GetStatus() =>
41+
public override Task<IEnumerable<HealthCheckStatus>> GetStatusAsync() =>
4242
Task.FromResult((IEnumerable<HealthCheckStatus>)new[] { CheckDocuments(false), CheckMedia(false) });
4343

4444
/// <inheritdoc />

src/Umbraco.Core/HealthChecks/Checks/Permissions/FolderAndFilePermissionsCheck.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public FolderAndFilePermissionsCheck(
3535
/// <summary>
3636
/// Get the status for this health check
3737
/// </summary>
38-
public override Task<IEnumerable<HealthCheckStatus>> GetStatus()
38+
public override Task<IEnumerable<HealthCheckStatus>> GetStatusAsync()
3939
{
4040
_filePermissionHelper.RunFilePermissionTestSuite(
4141
out Dictionary<FilePermissionTest, IEnumerable<string>> errors);

src/Umbraco.Core/HealthChecks/Checks/Security/BaseHttpHeaderCheck.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ protected BaseHttpHeaderCheck(
6262
/// <summary>
6363
/// Get the status for this health check
6464
/// </summary>
65-
public override async Task<IEnumerable<HealthCheckStatus>> GetStatus() =>
65+
public override async Task<IEnumerable<HealthCheckStatus>> GetStatusAsync() =>
6666
await Task.WhenAll(CheckForHeader());
6767

6868
/// <summary>

src/Umbraco.Core/HealthChecks/Checks/Security/ExcessiveHeadersCheck.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public ExcessiveHeadersCheck(ILocalizedTextService textService, IHostingEnvironm
3535
/// <summary>
3636
/// Get the status for this health check
3737
/// </summary>
38-
public override async Task<IEnumerable<HealthCheckStatus>> GetStatus() =>
38+
public override async Task<IEnumerable<HealthCheckStatus>> GetStatusAsync() =>
3939
await Task.WhenAll(CheckForHeaders());
4040

4141
/// <summary>

src/Umbraco.Core/HealthChecks/Checks/Security/HstsCheck.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public HstsCheck(IHostingEnvironment hostingEnvironment, ILocalizedTextService t
4343
protected override string ReadMoreLink => Constants.HealthChecks.DocumentationLinks.Security.HstsCheck;
4444

4545
/// <inheritdoc />
46-
public override async Task<IEnumerable<HealthCheckStatus>> GetStatus() =>
46+
public override async Task<IEnumerable<HealthCheckStatus>> GetStatusAsync() =>
4747
new HealthCheckStatus[] { await CheckForHeader() };
4848

4949
/// <summary>

0 commit comments

Comments
 (0)