mirror of https://github.com/Squidex/squidex.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
1.3 KiB
37 lines
1.3 KiB
// ==========================================================================
|
|
// Squidex Headless CMS
|
|
// ==========================================================================
|
|
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|
// All rights reserved. Licensed under the MIT license.
|
|
// ==========================================================================
|
|
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using Microsoft.Extensions.Diagnostics.HealthChecks;
|
|
using MongoDB.Driver;
|
|
|
|
namespace Squidex.Infrastructure.Diagnostics
|
|
{
|
|
public sealed class MongoDBHealthCheck : IHealthCheck
|
|
{
|
|
private readonly IMongoDatabase mongoDatabase;
|
|
|
|
public MongoDBHealthCheck(IMongoDatabase mongoDatabase)
|
|
{
|
|
this.mongoDatabase = mongoDatabase;
|
|
}
|
|
|
|
public async Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default)
|
|
{
|
|
var collectionNames = await mongoDatabase.ListCollectionNamesAsync(cancellationToken: cancellationToken);
|
|
|
|
var result = await collectionNames.AnyAsync(cancellationToken);
|
|
|
|
var status = result ?
|
|
HealthStatus.Healthy :
|
|
HealthStatus.Unhealthy;
|
|
|
|
return new HealthCheckResult(status, "Application must query data from MongoDB");
|
|
}
|
|
}
|
|
}
|
|
|