Files
sure/app/jobs/clear_ai_cache_job.rb
eureka928 23e9749ed1 Refactor clear_ai_cache to use family_scope pattern
- Move family-scoped queries to models via family_scope class method
- Remove hardcoded model names from Enrichable concern
- Replace inline rescue with proper respond_to? check
- Add count tracking for better logging
2026-01-26 10:17:28 +01:00

29 lines
832 B
Ruby

class ClearAiCacheJob < ApplicationJob
queue_as :low_priority
def perform(family)
if family.nil?
Rails.logger.warn("ClearAiCacheJob called with nil family, skipping")
return
end
Rails.logger.info("Clearing AI cache for family #{family.id}")
# Clear AI enrichment data for transactions
begin
count = Transaction.clear_ai_cache(family)
Rails.logger.info("Cleared AI cache for #{count} transactions")
rescue => e
Rails.logger.error("Failed to clear AI cache for transactions: #{e.message}")
end
# Clear AI enrichment data for entries
begin
count = Entry.clear_ai_cache(family)
Rails.logger.info("Cleared AI cache for #{count} entries")
rescue => e
Rails.logger.error("Failed to clear AI cache for entries: #{e.message}")
end
end
end