using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace ThreadPilot.Services
{
///
/// Service health status enumeration
///
public enum ServiceHealthStatus
{
Healthy,
Degraded,
Unhealthy,
Critical
}
///
/// Service health check result
///
public class ServiceHealthResult
{
public string ServiceName { get; set; } = string.Empty;
public ServiceHealthStatus Status { get; set; }
public string Description { get; set; } = string.Empty;
public TimeSpan ResponseTime { get; set; }
public DateTime CheckTime { get; set; }
public Exception? Exception { get; set; }
public Dictionary Data { get; set; } = new();
}
///
/// Interface for monitoring service health and lifecycle
///
public interface IServiceHealthMonitor
{
///
/// Register a service for health monitoring
///
void RegisterService(string serviceName, Func> healthCheck);
///
/// Unregister a service from health monitoring
///
void UnregisterService(string serviceName);
///
/// Perform health check on a specific service
///
Task CheckServiceHealthAsync(string serviceName);
///
/// Perform health check on all registered services
///
Task> CheckAllServicesHealthAsync();
///
/// Get the current health status of all services
///
Dictionary GetCurrentHealthStatus();
///
/// Event raised when a service health status changes
///
event EventHandler? ServiceHealthChanged;
}
///
/// Event arguments for service health changes
///
public class ServiceHealthChangedEventArgs : EventArgs
{
public string ServiceName { get; set; } = string.Empty;
public ServiceHealthStatus PreviousStatus { get; set; }
public ServiceHealthStatus CurrentStatus { get; set; }
public ServiceHealthResult HealthResult { get; set; } = new();
}
}