class TrendingIpsByPetitionJob < ApplicationJob - TrendingIpsByPetitionJob has no descriptive comment
delegate :enable_logging_of_trending_items?, to: :rate_limit
delegate :threshold_for_logging_trending_items, to: :rate_limit
delegate :threshold_for_notifying_trending_items, to: :rate_limit
delegate :ignore_ip?, to: :rate_limit
delegate :ignored_domains_list, to: :rate_limit
delegate :trending_ips_by_petition, to: :Signature
def perform(now = Time.current) -
- TrendingIpsByPetitionJob#perform has approx 10 statements
return unless enable_logging_of_trending_items?
trending_ips(now).each do |id, ips|
petition = Petition.find(id)
ips.each do |ip, count| - TrendingIpsByPetitionJob#perform contains iterators nested 2 deep
next unless ip.present?
next if ignore_ip?(ip)
begin
trending_ip = petition.trending_ips.log!(starts_at(now), ip, count)
if count >= threshold_for_notifying_trending_items
NotifyTrendingIpJob.perform_later(trending_ip)
end
rescue StandardError => e - TrendingIpsByPetitionJob#perform has the variable name 'e'
Appsignal.send_exception e
end
end
end
end
private
def rate_limit
@rate_limit ||= RateLimit.first_or_create!
end
def trending_ips(now)
trending_ips_by_petition(window(now), threshold_for_logging_trending_items, ignored_domains_list)
end
def petitions
Petition.where(id: petition_ids)
end
def window(now)
starts_at(now)..ends_at(now)
end
def starts_at(now)
@starts_at ||= ends_at(now).advance(hours: -1)
end
def ends_at(now)
@ends_at ||= now.at_beginning_of_hour
end
end