Class: LlmCostTracker::Doctor::IngestionCheck

Inherits:
Object
  • Object
show all
Defined in:
lib/llm_cost_tracker/doctor/ingestion_check.rb

Constant Summary collapse

PENDING_AGE_WARNING_SECONDS =
60

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(check_class) ⇒ IngestionCheck

Returns a new instance of IngestionCheck.



14
15
16
# File 'lib/llm_cost_tracker/doctor/ingestion_check.rb', line 14

def initialize(check_class)
  @check_class = check_class
end

Class Method Details

.call(check_class) ⇒ Object



10
11
12
# File 'lib/llm_cost_tracker/doctor/ingestion_check.rb', line 10

def self.call(check_class)
  new(check_class).call
end

Instance Method Details

#callObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/llm_cost_tracker/doctor/ingestion_check.rb', line 18

def call
  return unless llm_api_calls_table?

  missing = missing_parts
  if missing.empty?
    quarantined = quarantined_count
    if quarantined.positive?
      return check_class.new(:warn, "durable ingestion", "#{quarantined} inbox events quarantined after retries")
    end

    pending = pending_snapshot
    if stale_pending?(pending)
      return check_class.new(
        :warn,
        "durable ingestion",
        "#{pending.fetch(:count)} inbox events pending; oldest pending age #{pending_age(pending).round}s"
      )
    end

    return check_class.new(:ok, "durable ingestion", "inbox and ingestor lease tables available")
  end

  check_class.new(
    :warn,
    "durable ingestion",
    "missing #{missing.join(', ')}; run bin/rails generate llm_cost_tracker:add_ingestion && bin/rails db:migrate"
  )
end