Module: LlmCostTracker::PriceFreshness

Defined in:
lib/llm_cost_tracker/price_freshness.rb

Constant Summary collapse

STALE_AFTER_DAYS =
30

Class Method Summary collapse

Class Method Details

.call(metadata, today: Date.today) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/llm_cost_tracker/price_freshness.rb', line 10

def call(, today: Date.today)
  updated_at = ["updated_at"] || [:updated_at]
  return missing unless updated_at

  date = Date.iso8601(updated_at.to_s)
  age_days = (today - date).to_i
  return stale(updated_at) if age_days > STALE_AFTER_DAYS

  [:ok, "updated_at=#{updated_at}"]
rescue Date::Error
  [:warn, "metadata.updated_at=#{updated_at.inspect} is invalid; run bin/rails llm_cost_tracker:prices:sync"]
end