Raccoglie eventi aggregati dietro consenso cookie, senza PII né tracking su admin/regia/live/replay; GA4 resta invariato. Co-authored-by: Cursor <cursoragent@cursor.com>
26 lines
660 B
Ruby
26 lines
660 B
Ruby
# frozen_string_literal: true
|
|
|
|
module Analytics
|
|
class AggregateJob < ApplicationJob
|
|
queue_as :default
|
|
|
|
def perform(purge: false)
|
|
redis = Redis.new(url: ENV.fetch("REDIS_URL", "redis://localhost:6379/0"))
|
|
lock_key = "analytics:aggregate:lock"
|
|
acquired = redis.set(lock_key, "1", nx: true, ex: 120)
|
|
return unless acquired
|
|
|
|
begin
|
|
service = Analytics::Aggregate.new
|
|
service.call
|
|
service.purge_old! if purge
|
|
ensure
|
|
redis.del(lock_key)
|
|
end
|
|
rescue StandardError => e
|
|
Rails.logger.error("[analytics] aggregate failed: #{e.class} #{e.message}")
|
|
raise
|
|
end
|
|
end
|
|
end
|