Module: Pigeon::HealthCheck::Processor

Defined in:
lib/pigeon/health_check/processor.rb

Overview

Processor health check functionality

Class Method Summary collapse

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

Parameters:

  • stats (Hash)

    Statistics hash to update



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

.healthHash

Check the health of the processor

Returns:

  • (Hash)

    Health check result



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, message = status(processor_running, stats)

  {
    component: "processor",
    status: status,
    message: message,
    details: stats
  }
end

.statistics(processor_running) ⇒ Hash

Get processor statistics

Parameters:

  • processor_running (Boolean)

    Whether the processor is running

Returns:

  • (Hash)

    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

Parameters:

  • processor_running (Boolean)

    Whether the processor is running

  • stats (Hash)

    Processor statistics

Returns:

  • (Array<String, String>)

    Status and message



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