Class: LlmCostTracker::CallRollup
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- LlmCostTracker::CallRollup
- Defined in:
- app/models/llm_cost_tracker/call_rollup.rb
Class Method Summary collapse
Class Method Details
.decrement(buckets) ⇒ Object
10 11 12 13 14 15 16 |
# File 'app/models/llm_cost_tracker/call_rollup.rb', line 10 def decrement(buckets) now = Time.now.utc buckets.each do |(period, period_start, currency, provider), amount| where(period: period, period_start: period_start, currency: currency, provider: provider) .update_all(["total_cost = GREATEST(0, total_cost - ?), updated_at = ?", amount, now]) end end |
.increment_all(rows) ⇒ Object
6 7 8 |
# File 'app/models/llm_cost_tracker/call_rollup.rb', line 6 def increment_all(rows) upsert_all(rows, on_duplicate: increment_on_duplicate, record_timestamps: true, unique_by: increment_unique_by) end |