Module: LlmCostTracker::Ingestion

Defined in:
lib/llm_cost_tracker/ingestion.rb,
lib/llm_cost_tracker/ingestion/pool.rb,
lib/llm_cost_tracker/ingestion/batch.rb,
lib/llm_cost_tracker/ingestion/inbox.rb,
lib/llm_cost_tracker/ingestion/worker.rb,
lib/llm_cost_tracker/ingestion/lease_claim.rb,
app/models/llm_cost_tracker/ingestion/lease.rb,
app/models/llm_cost_tracker/ingestion/inbox_entry.rb

Defined Under Namespace

Modules: Pool Classes: Batch, Inbox, InboxEntry, Lease, LeaseClaim, Worker

Constant Summary collapse

VERIFY_TAG =
"llm_cost_tracker_verify"
CORE_SCHEMA_GUARDS =
[
  ["llm_cost_tracker_calls",           Ledger::Schema::Calls],
  ["llm_cost_tracker_call_line_items", Ledger::Schema::CallLineItems],
  ["llm_cost_tracker_call_tags",       Ledger::Schema::CallTags]
].freeze
ROLLUPS_SCHEMA_GUARD =
["llm_cost_tracker_call_rollups", Ledger::Schema::CallRollups].freeze
ASYNC_SCHEMA_GUARDS =
[
  ["llm_cost_tracker_ingestion_inbox_entries", Ledger::Schema::IngestionInboxEntries],
  ["llm_cost_tracker_ingestion_leases",        Ledger::Schema::IngestionLeases]
].freeze

Class Method Summary collapse

Class Method Details

.async?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/llm_cost_tracker/ingestion.rb', line 49

def async?
  LlmCostTracker.configuration.ingestion == :async
end

.cache_rollups?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/llm_cost_tracker/ingestion.rb', line 53

def cache_rollups?
  LlmCostTracker.configuration.cache_rollups
end

.ensure_current_schema!Object



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/llm_cost_tracker/ingestion.rb', line 35

def ensure_current_schema!
  unless LlmCostTracker::Call.table_exists?
    raise Error, "llm_cost_tracker_calls table is missing; run install generator and migrate"
  end

  guards_for_current_config.each do |table_name, schema_module|
    errors = schema_module.current_schema_errors
    next if errors.empty?

    raise Error,
          "#{table_name} table is not on the current schema: #{errors.join('; ')}; see docs/upgrading.md"
  end
end

.guards_for_current_configObject



57
58
59
60
61
62
# File 'lib/llm_cost_tracker/ingestion.rb', line 57

def guards_for_current_config
  guards = CORE_SCHEMA_GUARDS.dup
  guards << ROLLUPS_SCHEMA_GUARD if cache_rollups?
  guards += ASYNC_SCHEMA_GUARDS if async?
  guards
end

.table_name_prefixObject



18
19
20
# File 'lib/llm_cost_tracker/ingestion.rb', line 18

def table_name_prefix
  "llm_cost_tracker_ingestion_"
end

.verifyObject



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/llm_cost_tracker/ingestion.rb', line 64

def verify
  unless LlmCostTracker::Call.table_exists?
    return [
      LlmCostTracker::Doctor::Check.new(
        :error,
        "active_record",
        "llm_cost_tracker_calls table is missing; run install generator and migrate"
      )
    ]
  end

  [capture_check]
rescue StandardError => e
  [LlmCostTracker::Doctor::Check.new(:error, "active_record", "#{e.class}: #{e.message}")]
end