Browse Source

Use `IAbpApplicationConfigurationAppService` to check website health.

pull/270/head
maliming 2 years ago
parent
commit
aa004c5dab
No known key found for this signature in database GPG Key ID: A646B9CB645ECEA4
  1. 13
      apps/public-web/src/EShopOnAbp.PublicWeb/HealthChecks/EShopOnAbpHealthCheck.cs

13
apps/public-web/src/EShopOnAbp.PublicWeb/HealthChecks/EShopOnAbpHealthCheck.cs

@ -2,25 +2,28 @@
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.Extensions.Diagnostics.HealthChecks; using Microsoft.Extensions.Diagnostics.HealthChecks;
using Volo.Abp.AspNetCore.Mvc.ApplicationConfigurations;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
using Volo.Abp.Identity;
namespace EShopOnAbp.PublicWeb.HealthChecks; namespace EShopOnAbp.PublicWeb.HealthChecks;
public class EShopOnAbpHealthCheck : IHealthCheck, ITransientDependency public class EShopOnAbpHealthCheck : IHealthCheck, ITransientDependency
{ {
protected readonly IIdentityUserAppService IdentityUserAppService; protected readonly IAbpApplicationConfigurationAppService ApplicationConfigurationAppService;
public EShopOnAbpHealthCheck(IIdentityUserAppService identityUserAppService) public EShopOnAbpHealthCheck(IAbpApplicationConfigurationAppService applicationConfigurationAppService)
{ {
IdentityUserAppService = identityUserAppService; ApplicationConfigurationAppService = applicationConfigurationAppService;
} }
public async Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default) public async Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default)
{ {
try try
{ {
await IdentityUserAppService.GetListAsync(new GetIdentityUsersInput { MaxResultCount = 1 }); await ApplicationConfigurationAppService.GetAsync(new ApplicationConfigurationRequestOptions()
{
IncludeLocalizationResources = false
});
return HealthCheckResult.Healthy($"Could connect to database and get record."); return HealthCheckResult.Healthy($"Could connect to database and get record.");
} }

Loading…
Cancel
Save