Module: Pigeon::HealthCheck::Processor
- Defined in:
- lib/pigeon/health_check/processor.rb
Overview
Processor health check functionality
Class Method Summary collapse
-
.add_error_rate_to_stats(stats) ⇒ void
Add error rate to statistics if metrics are available.
-
.health ⇒ Hash
Check the health of the processor.
-
.statistics(processor_running) ⇒ Hash
Get processor statistics.
-
.status(processor_running, stats) ⇒ Array<String, String>
Determine processor status.
Class Method Details
.add_error_rate_to_stats(stats) ⇒ void
This method returns an undefined value.
Add error rate to statistics if metrics are available
46 47 48 49 50 51 52 53 |
# File 'lib/pigeon/health_check/processor.rb', line 46 def self.add_error_rate_to_stats(stats) return unless Pigeon.config.metrics_collector total_processed = Pigeon.metrics_collector.get_counter(:messages_processed_total) || 0 total_failed = Pigeon.metrics_collector.get_counter(:messages_failed_total) || 0 stats[:error_rate] = total_processed.positive? ? (total_failed.to_f / total_processed) : 0 end |
.health ⇒ Hash
Check the health of the processor
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/pigeon/health_check/processor.rb', line 9 def self.health processor_running = Pigeon.processing? # Get processor statistics stats = statistics(processor_running) # Determine overall status status, = status(processor_running, stats) { component: "processor", status: status, message: , details: stats } end |
.statistics(processor_running) ⇒ Hash
Get processor statistics
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/pigeon/health_check/processor.rb', line 29 def self.statistics(processor_running) stats = { running: processor_running, uptime_seconds: processor_running ? (Time.now - Pigeon.processor_start_time).to_i : 0, last_run_at: Pigeon.last_processing_run, last_successful_run_at: Pigeon.last_successful_processing_run } # Add error rate if metrics are available add_error_rate_to_stats(stats) stats end |
.status(processor_running, stats) ⇒ Array<String, String>
Determine processor status
59 60 61 62 63 64 65 66 67 |
# File 'lib/pigeon/health_check/processor.rb', line 59 def self.status(processor_running, stats) if !processor_running ["critical", "Processor is not running"] elsif stats[:last_run_at].nil? || (Time.now - stats[:last_run_at]) > 300 # 5 minutes ["warning", "Processor has not run in the last 5 minutes"] else ["healthy", "Processor is running normally"] end end |