902942eee6
continuous-integration/drone/pr Build is passing
Sealed qualifying public classes Migrated database changes
29 lines
1.2 KiB
C#
29 lines
1.2 KiB
C#
using static LiteCharms.Features.Extensions.Quartz;
|
|
|
|
namespace LiteCharms.Features.MidrandBooks.HealthChecks;
|
|
|
|
public sealed class MidrandShopQuartzHealthCheck(ISchedulerFactory schedulerFactory) : IHealthCheck
|
|
{
|
|
public async Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default)
|
|
{
|
|
try
|
|
{
|
|
var scheduler = await schedulerFactory.GetScheduler(MidrandShopSchedulerName, cancellationToken);
|
|
|
|
if(scheduler == null)
|
|
return HealthCheckResult.Unhealthy($"Scheduler with name '{MidrandShopSchedulerName}' not found.");
|
|
|
|
if (!scheduler.IsStarted)
|
|
return HealthCheckResult.Unhealthy($"{MidrandShopSchedulerName} Quartz scheduler is not running");
|
|
|
|
await scheduler.CheckExists(new JobKey(Guid.NewGuid().ToString()), cancellationToken);
|
|
|
|
return HealthCheckResult.Healthy($"{MidrandShopSchedulerName} Quartz scheduler is ready");
|
|
}
|
|
catch (SchedulerException)
|
|
{
|
|
return HealthCheckResult.Unhealthy($"{MidrandShopSchedulerName} Quartz scheduler cannot connect to the store");
|
|
}
|
|
}
|
|
}
|