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

Instance Method Summary collapse

Instance Method Details

#callObject



12
13
14
15
16
17
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
# File 'lib/llm_cost_tracker/doctor/ingestion_check.rb', line 12

def call
  return unless Probe.table_exists?("llm_cost_tracker_calls")

  missing = missing_parts
  if missing.empty?
    inbox = inbox_snapshot
    quarantined = inbox.try(:quarantined_count).to_i
    if quarantined.positive?
      return Check.new(:warn, "durable ingestion", "#{quarantined} inbox entries quarantined after retries")
    end

    pending_count = inbox.try(:pending_count).to_i
    oldest_pending_at = inbox.try(:oldest_pending_at)&.to_time&.utc
    pending_age = oldest_pending_at && (Time.now.utc - oldest_pending_at)
    if pending_count.positive? && pending_age && pending_age >= PENDING_AGE_WARNING_SECONDS
      return Check.new(
        :warn,
        "durable ingestion",
        "#{pending_count} inbox entries pending; oldest pending age #{pending_age.round}s"
      )
    end

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

  Check.new(
    :error,
    "durable ingestion",
    "missing #{missing.join(', ')}; see docs/upgrading.md for the recovery steps"
  )
end