Class: Hungrytable::ApiHealthMonitor
- Inherits:
-
Object
- Object
- Hungrytable::ApiHealthMonitor
- Defined in:
- lib/hungrytable/api_health_monitor.rb
Overview
Monitors API health and detects potential deprecation or degradation
Class Method Summary collapse
-
.check_status ⇒ Symbol
Perform a lightweight health check.
-
.health_check ⇒ Hash
Check if API is healthy.
-
.log_health(logger = nil) ⇒ Object
Log API health to stdout or logger.
-
.warnings ⇒ Array<Hash>
Get warnings about potential issues.
Class Method Details
.check_status ⇒ Symbol
Perform a lightweight health check
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/hungrytable/api_health_monitor.rb', line 21 def check_status return :down if CircuitBreaker.open? begin # Try a simple request restaurant = Restaurant.new(82591) restaurant.valid? ? :healthy : :degraded rescue UnauthorizedError :unauthorized rescue ServerError, HTTPError :down rescue StandardError :unknown end end |
.health_check ⇒ Hash
Check if API is healthy
9 10 11 12 13 14 15 16 17 |
# File 'lib/hungrytable/api_health_monitor.rb', line 9 def health_check { timestamp: Time.now.utc.iso8601, status: check_status, circuit_breaker: CircuitBreaker.stats, endpoint: Config.base_url, warnings: warnings } end |
.log_health(logger = nil) ⇒ Object
Log API health to stdout or logger
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/hungrytable/api_health_monitor.rb', line 71 def log_health(logger = nil) health = health_check output = logger || $stdout case health[:status] when :healthy output.puts "[Hungrytable] API Status: HEALTHY" when :degraded output.puts "[Hungrytable] API Status: DEGRADED - Some endpoints may be failing" when :down output.puts "[Hungrytable] API Status: DOWN - API is not responding" when :unauthorized output.puts "[Hungrytable] API Status: UNAUTHORIZED - Check credentials" else output.puts "[Hungrytable] API Status: UNKNOWN" end health[:warnings].each do |warning| output.puts "[Hungrytable] [#{warning[:level].to_s.upcase}] #{warning[:message]}" end end |
.warnings ⇒ Array<Hash>
Get warnings about potential issues
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/hungrytable/api_health_monitor.rb', line 39 def warnings warnings = [] if CircuitBreaker.open? warnings << { level: :critical, message: 'Circuit breaker is OPEN - API appears to be down', action: 'Wait for circuit breaker timeout or contact OpenTable support' } end if check_oauth_version_deprecated? warnings << { level: :warning, message: 'Using OAuth 1.0 which may be deprecated', action: 'Consider migrating to modern OpenTable API (OAuth 2.0)' } end if check_legacy_endpoint? warnings << { level: :warning, message: 'Using legacy otapi_v3.ashx endpoint (2012 vintage)', action: 'Verify endpoint is still supported with OpenTable' } end warnings end |