24 lines
848 B
C#
24 lines
848 B
C#
namespace LiteCharms.Features.HealthChecks;
|
|
|
|
public class QuartzHealthCheck(ISchedulerFactory schedulerFactory) : IHealthCheck
|
|
{
|
|
public async Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default)
|
|
{
|
|
try
|
|
{
|
|
var scheduler = await schedulerFactory.GetScheduler(cancellationToken);
|
|
|
|
if (!scheduler.IsStarted)
|
|
return HealthCheckResult.Unhealthy("Quartz scheduler is not running");
|
|
|
|
await scheduler.CheckExists(new JobKey(Guid.NewGuid().ToString()), cancellationToken);
|
|
|
|
return HealthCheckResult.Healthy("Quartz scheduler is ready");
|
|
}
|
|
catch (SchedulerException)
|
|
{
|
|
return HealthCheckResult.Unhealthy("Quartz scheduler cannot connect to the store");
|
|
}
|
|
}
|
|
}
|