Class: Tasker::HealthController

Inherits:
ApplicationController show all
Defined in:
app/controllers/tasker/health_controller.rb

Overview

Health check controller providing endpoints for system health monitoring.

This controller provides three health check endpoints:

  • ‘/health/ready` - Readiness check (K8s probes, always unauthenticated)

  • ‘/health/live` - Liveness check (K8s probes, always unauthenticated)

  • ‘/health/status` - Detailed status (uses system_status.read authorization)

The status endpoint uses the authorization system with the ‘system_status.read` permission. If authorization is disabled or no authorization coordinator is configured, access is allowed. If authorization is enabled, users need the `tasker.system_status:read` permission.

Instance Method Summary collapse

Instance Method Details

#liveJSON

Liveness check endpoint for Kubernetes probes Always returns 200 OK and doesn’t require authentication/authorization

Returns:

  • (JSON)

    Simple alive status



52
53
54
55
56
57
58
# File 'app/controllers/tasker/health_controller.rb', line 52

def live
  render json: {
    alive: true,
    timestamp: Time.current.iso8601,
    service: 'tasker'
  }, status: :ok
end

#readyJSON

Readiness check endpoint for Kubernetes probes Always returns quickly and doesn’t require authentication/authorization

Returns:

  • (JSON)

    Simple ready/not ready status



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/controllers/tasker/health_controller.rb', line 31

def ready
  result = Tasker::Health::ReadinessChecker.ready?

  if result[:ready]
    render json: result, status: :ok
  else
    render json: result, status: :service_unavailable
  end
rescue StandardError => e
  render json: {
    ready: false,
    error: 'Health check failed',
    message: e.message,
    timestamp: Time.current.iso8601
  }, status: :service_unavailable
end

#statusJSON

Detailed status endpoint with comprehensive system metrics (cached) Uses system_status.read authorization if authorization is enabled Results are cached using IntelligentCacheManager for performance

Returns:

  • (JSON)

    Detailed system status and metrics



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'app/controllers/tasker/health_controller.rb', line 65

def status
  # Use intelligent caching for expensive system status analysis
  cache_key = "tasker:health:detailed_status:#{system_status_cache_version}"

  cached_result = @intelligent_cache.intelligent_fetch(cache_key, base_ttl: 60.seconds) do
    status_result = Tasker::Health::StatusChecker.status

    # Enhance with additional performance analytics
    enhanced_result = enhance_status_with_analytics(status_result)

    {
      **enhanced_result,
      generated_at: Time.current,
      cache_info: {
        cached: true,
        cache_key: cache_key,
        ttl_base: '5 minutes'
      }
    }
  end

  if cached_result[:healthy]
    render json: cached_result, status: :ok
  else
    render json: cached_result, status: :service_unavailable
  end
rescue StandardError => e
  render json: {
    healthy: false,
    error: 'Status check failed',
    message: e.message,
    timestamp: Time.current.iso8601
  }, status: :service_unavailable
end