Class: LlmCostTracker::Storage::ActiveRecordBackend
- Inherits:
-
Object
- Object
- LlmCostTracker::Storage::ActiveRecordBackend
- Defined in:
- lib/llm_cost_tracker/storage/active_record_backend.rb
Constant Summary collapse
- VERIFY_TAG =
"llm_cost_tracker_verify"
Class Method Summary collapse
Class Method Details
.prune(cutoff:, batch_size:) ⇒ Object
50 51 52 53 54 |
# File 'lib/llm_cost_tracker/storage/active_record_backend.rb', line 50 def prune(cutoff:, batch_size:) require_relative "../llm_api_call" unless defined?(LlmCostTracker::LlmApiCall) ActiveRecordStore.prune(cutoff: cutoff, batch_size: batch_size) end |
.save(event) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/llm_cost_tracker/storage/active_record_backend.rb', line 17 def save(event) require_relative "../llm_api_call" unless defined?(LlmCostTracker::LlmApiCall) if ActiveRecordInbox.enabled? ActiveRecordInbox.save(event) else ActiveRecordStore.save(event) end event rescue LoadError => e raise Error, "ActiveRecord storage requires the active_record gem: #{e.}" end |
.verify ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/llm_cost_tracker/storage/active_record_backend.rb', line 30 def verify require_relative "../llm_api_call" unless defined?(LlmCostTracker::LlmApiCall) unless LlmCostTracker::LlmApiCall.table_exists? return [ VerificationResult.new( :error, "active_record", "llm_api_calls table is missing; run install generator and migrate" ) ] end [active_record_capture_check] rescue LoadError => e [VerificationResult.new(:error, "active_record", "unavailable: #{e.}")] rescue StandardError => e [VerificationResult.new(:error, "active_record", "#{e.class}: #{e.}")] end |