Class: LlmCostTracker::Reconciliation::Importer
- Inherits:
-
Object
- Object
- LlmCostTracker::Reconciliation::Importer
- Defined in:
- lib/llm_cost_tracker/reconciliation/importer.rb
Constant Summary collapse
- REQUIRED_FIELDS =
%i[external_id period_start period_end].freeze
- FORGIVING_METADATA_SOURCES =
%i[csv].to_set.freeze
- ENVELOPE_KEYS =
%w[row_type meter authority match_basis].freeze
Instance Method Summary collapse
- #call(rows) ⇒ Object
-
#initialize(source:, imported_at:, provider:, window: nil, strict_metadata: nil, cursor: nil) ⇒ Importer
constructor
A new instance of Importer.
Constructor Details
#initialize(source:, imported_at:, provider:, window: nil, strict_metadata: nil, cursor: nil) ⇒ Importer
Returns a new instance of Importer.
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/llm_cost_tracker/reconciliation/importer.rb', line 18 def initialize(source:, imported_at:, provider:, window: nil, strict_metadata: nil, cursor: nil) @source = source.to_s @provider = provider.to_s @imported_at = imported_at @window = coerce_window(window) @cursor = cursor @strict_metadata = .nil? ? !FORGIVING_METADATA_SOURCES.include?(source.to_sym) : raise ArgumentError, "source must be present" if @source.empty? raise ArgumentError, "provider must be present" if @provider.empty? end |
Instance Method Details
#call(rows) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/llm_cost_tracker/reconciliation/importer.rb', line 29 def call(rows) import_record = nil ensure_reconciliation_installed! return ImportResult.empty if skippable?(rows) import_record = open_import_record result = perform_import(rows) complete_import_record(import_record, result) result.with(import_id: import_record&.id) rescue StandardError => e fail_import_record(import_record, e) raise end |