Module: LlmCostTracker::Retention
- Defined in:
- lib/llm_cost_tracker/retention.rb
Constant Summary collapse
- DEFAULT_BATCH_SIZE =
5_000
Class Method Summary collapse
Class Method Details
.prune(older_than:, batch_size: DEFAULT_BATCH_SIZE, now: Time.now.utc) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/llm_cost_tracker/retention.rb', line 8 def prune(older_than:, batch_size: DEFAULT_BATCH_SIZE, now: Time.now.utc) cutoff = resolve_cutoff(older_than, now) require_relative "llm_api_call" unless defined?(LlmCostTracker::LlmApiCall) deleted = 0 loop do batch = LlmCostTracker::LlmApiCall.where(tracked_at: ...cutoff).limit(batch_size).delete_all deleted += batch break if batch < batch_size end deleted end |